我有一个页面可以在window.onload上设置一些事件: 函数prepEvents() { document.getElementById(" menumap_sales")。onmouseov er = swapMenuSales; // etc } window.onload = prepEvents; 效果很好,直到现在加载此javascript src的页面 包含一个iframe。看来document.getElementById()调用 现在返回null。如果我删除iframe,它会再次起作用。 大概这与现在拥有多个文件有关, 但是如何访问我想要的那个? 感谢您的帮助! Andy C
I had a page that does some event setup on window.onload: function prepEvents() { document.getElementById("menumap_sales").onmouseov er = swapMenuSales; // etc } window.onload = prepEvents; worked great, until the page where this javascript src is loaded now contains an iframe. It seems that the document.getElementById() call is returning null now. If I remove the iframe, it all works again. Presumably it''s something to do with having multiple documents now, but how do I access the one I want? Thanks for your help! Andy C
推荐答案ACaécrit: AC a écrit : 我有一个页面可以在window.onload上进行一些事件设置: 函数prepEvents() { document.getElementById(" menumap_sales")。onmouseov er = swapMenuSales; //等 } window.onload = prepEvents; 效果很好,直到现在加载此javascript src的页面 包含iframe。看来document.getElementById()调用 现在返回null。如果我删除iframe,它会再次起作用。 大概这与现在拥有多个文件有关, 但是如何访问我想要的那个? I had a page that does some event setup on window.onload: function prepEvents() { document.getElementById("menumap_sales").onmouseov er = swapMenuSales; // etc } window.onload = prepEvents; worked great, until the page where this javascript src is loaded now contains an iframe. It seems that the document.getElementById() call is returning null now. If I remove the iframe, it all works again. Presumably it''s something to do with having multiple documents now, but how do I access the one I want?
页面中只有一个同名的ID! 如果这样,你就无法访问iframe中加载的文件文件来自另一个 域的主文件。
only one ID of same name in a page ! you can''t acces file loaded in iframes if this file is from another domain that the main file.
> > 页面中只有一个同名的ID! only one ID of same name in a page !
是的,没有重复的ID。
yep there are no repeated ids.
如果此文件来自主文件的另一个 域,则无法访问iframe中加载的文件。 you can''t acces file loaded in iframes if this file is from another domain that the main file.同意。两者都在我的网站的根目录中。 HTML是这样的: < html> < script language =" JavaScript"类型= QUOT;文本/ JavaScript的" src =" script / menu.js">< / script> < body> < form> < div id =" pagebody"> < div id =" loginlinks"> < iframe src = " chat.html" FRAMEBORDER =" 0" scrolling =" no" id =" chatFrame"名称= QUOT; chatFrame" /> < / div> < / div> < / body> < / html> 可能与时间有关吗?即onload事件是在DOM对象准备好之前调用 ??? 我现在完全不知所措;添加一个iframe应该是 简单的位... 帮助! TIA, AC
agreed. Both are in the root of my site. HTML goes like this: <html> <script language="JavaScript" type="text/javascript" src="script/ menu.js"></script> <body> <form> <div id="pagebody"> <div id="loginlinks"> <iframe src="chat.html" frameborder="0" scrolling="no" id="chatFrame" name="chatFrame" /> </div> </div> </body> </html> Could it be something to do with timing? i.e. the onload event is being called before the DOM object is ready??? I''m completely at a loss at the moment; adding an iframe should be the easy bit... Help! TIA, AC
ACaécrit: AC a écrit : >只有一个ID在一个页面中同名! >only one ID of same name in a page !
是的,没有重复的ID。
yep there are no repeated ids.
>你可以如果此文件来自主文件的另一个域,则访问iframe中加载的文件。 >you can''t acces file loaded in iframes if this file is from anotherdomain that the main file.同意。两者都在我的网站的根目录中。 HTML是这样的: < html> < script language =" JavaScript"类型= QUOT;文本/ JavaScript的" src =" script / menu.js">< / script> < body> < form>
agreed. Both are in the root of my site. HTML goes like this: <html> <script language="JavaScript" type="text/javascript" src="script/ menu.js"></script> <body> <form>
这个开头的表格标签是什么? (无处可关闭)
what is this opening form tag ? (with nowhere a closing one)
< div id =" pagebody"> < div id =" loginlinks"> < iframe src =" chat html的" FRAMEBORDER =" 0" scrolling =" no" id =" chatFrame"名称= QUOT; chatFrame" /> < / div> < / div> < / body> < / html> 可能与时间有关吗?即onload事件是在DOM对象准备好之前调用 ??? 我现在完全不知所措;添加一个iframe应该是 easy bit ... <div id="pagebody"> <div id="loginlinks"> <iframe src="chat.html" frameborder="0" scrolling="no" id="chatFrame" name="chatFrame" /> </div> </div> </body> </html> Could it be something to do with timing? i.e. the onload event is being called before the DOM object is ready??? I''m completely at a loss at the moment; adding an iframe should be the easy bit...它是获取onload功能的主页吗? 我看不到元素''menumap_sales''......! - sm
is it the main page which gets the onload function ? I see nowhere the element ''menumap_sales'' ... ! -- sm
更多推荐
添加iframe后,document.getElementById停止工作
发布评论