Robin Carlo Catacutan
Robin Carlo Catacutan

Reputation: 13679

IFrame Undefined value on body onload

How can I get the value of my iframe using body onload, I get an undefined value.

my non-working code:

index.html

<body onload ="loadThis()">

      <iframe id = "myframe" src = "sample.html"></iframe>

</body>

my.js

function loadThis(){

      var doc = window.frames['myframe'].document.getElementById('userID').innerHTML;

      alert(doc);

}

The function "loadThis()" runs before the Iframe is loaded. How can I get this working?

Upvotes: 0

Views: 2092

Answers (1)

khael
khael

Reputation: 2610

You should do this:

<body >

  <iframe onload ="loadThis()" id = "myframe" src = "sample.html"></iframe>

</body>

Upvotes: 2

Related Questions