dynamic设置iframe src
我有一个程序,将dynamic设置一个iframe src来加载页面。 我需要挂钩完全加载页面的事件处理程序。 我该怎么做? 谢谢!
<script type="text/javascript"> function iframeDidLoad() { alert('Done'); } function newSite() { var sites = ['http://getprismatic.com', 'http://gizmodo.com/', 'http://lifehacker.com/'] document.getElementById('myIframe').src = sites[Math.floor(Math.random() * sites.length)]; } </script> <input type="button" value="Change site" onClick="newSite()" /> <iframe id="myIframe" src="http://getprismatic.com/" onLoad="iframeDidLoad();"></iframe>
尝试这个…
function urlChange(url) { var site = url+'?toolbar=0&navpanes=0&scrollbar=0'; document.getElementById('iFrameName').src = site; } <a href="javascript:void(0);" onClick="urlChange('www.mypdf.com/test.pdf')">TEST </a>
尝试这个:
top.document.getElementById('AppFrame').setAttribute("src",fullPath);
尝试这个:
document.frames["myiframe"].onload = function(){ alert("Hello World"); }
你也应该考虑在一些Opera版本中,onload被激发了几次,并添加了一些钩子:
// fixing Opera 9.26, 10.00 if (doc.readyState && doc.readyState != 'complete') { // Opera fires load event multiple times // Even when the DOM is not ready yet // this fix should not affect other browsers return; } // fixing Opera 9.64 if (doc.body && doc.body.innerHTML == "false") { // In Opera 9.64 event was fired second time // when body.innerHTML changed from false // to server response approx. after 1 sec return; }
从Ajax上传中借用的代码