iframe onload event
I have a pa开发者_如何学运维ge which has the structure like this;
<body onLoad="LoadPage()">
<iframe src="pg1.html">
<p>Your browser does not support iframes.</p>
</iframe>
<iframe src="about:blank">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
Now on body load, I set the "src" value for the 2nd iframe. If I call body onload, the function seems to be getting called twice...So is there any other way by which I can call the function to set the src..
<script type="text/javascript">
function LoadPage(){
var pdfVal = document.forms[0].pdf_val.value;
document.getElementById('ipad_pdf_link').href = pdfVal;
}
</script>
I'm not sure why it loads twice, but you can, instead of doing it on the onLoad
, use jQuery:
<script>
function loadPage() {
var pdfVal = $("name=[pdf_val]").val();
$('#ipad_pdf_link').attr("src", pdfVal);
}
$(function() { // called when the page finishes loading
loadPage();
});
</script>
jQuery is much more robust to handle browser differences and i'm sure will save you a lot of headaches in the future.
Reference:
- How jQuery works
You could put
<script type="text/javascript">
LoadPage();
</script>
At the bottom of the HTML, instead of on the onload event, and it will still get called when the page has finished loading.
Loading twice is most likely related to this: http://msdn.microsoft.com/en-us/library/ie/hh180173%28v=vs.85%29.aspx
I have a case where IE9 calls init function twice, when it is set with <body onload="x()">
. We have a system, where our old asp-pages run in iframe, and there are dozens of them. All of them use the same old syntax. First init call is made correctly, but the second one is done as top-most. This basically messes things up, because in the iframe window.top does not have functions that there should be, because it is the iframe window itself. In IE8, IE9's IE8 mode, Chrome and Firefox it works fine.
精彩评论