等待iframe加载JavaScript [英] Wait for iframe to load in JavaScript
问题描述
righttop.location =timesheet_notes.php;
然后要传递信息给它:
righttop.document.notesform.ID_client.value =客户端;
显然,该行在iframe中的页面已经完整载入之前不会工作,那个表单元素是要写的。
那么,解决这个问题的最好/最有效的方法是什么?某种超时循环?理想情况下,我真的希望将其全部包含在这个特定的脚本中,而不必在打开的页面上添加任何额外的东西。
首先,我相信你应该影响iframe的 src
属性,而不是位置
。其次,钩住iframe的加载
事件来执行您的更改:
myIframe.addEventListener(load,function(){
this.contentWindow.document.notesform.ID_client.value = Client;
});
myIframe.src ='timesheet_notes.php';
再次,这一切都是假设你的意思是我框架,而不是框架集。
I am opening an iframe in JavaScript:
righttop.location = "timesheet_notes.php";
and then want to pass information to it:
righttop.document.notesform.ID_client.value = Client;
Obviously though, that line isn't going to work until the page has fully loaded in the iframe, and that form element is there to be written to.
So, what is the best/most efficient way to address this? Some sort of timeout loop? Ideally I would really like to keep it all contained within this particular script, rather than having to add any extra stuff to the page that is being opened.
First of all, I believe you are supposed to affect the src
property of iframes, not location
. Second of all, hook the iframe's load
event to perform your changes:
var myIframe = document.getElementById('righttop');
myIframe.addEventListener("load", function() {
this.contentWindow.document.notesform.ID_client.value = Client;
});
myIframe.src = 'timesheet_notes.php';
Again, this is all presuming you mean iframe, not framesets.
这篇关于等待iframe加载JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!