Reputation: 13679
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
Reputation: 2610
You should do this:
<body >
<iframe onload ="loadThis()" id = "myframe" src = "sample.html"></iframe>
</body>
Upvotes: 2