Internet Explorer Dom 元素 getElementById
在 Internet Explorer 8 下,当我尝试将 Div 从窗口复制到弹出窗口时,getElementById 方法不会返回 DOM 元素,而是返回普通元素。我无法对此类项目调用appendChild,因为我收到“非法参数”错误。将 div 从父窗口复制到子弹出窗口的解决方案是什么?
到目前为止,我编写的代码可以在 Chrome 和 Firefox 上完美运行,但不能在 IE 上运行。
此代码位于弹出窗口中:
加载弹出窗口时调用此代码
<body onload="initialize();">
<div id='sourceDiv'></div>
</body>
function initialize(){
var source = window.opener.document;
var myDiv = source.getElementById("myDiv");
var destination = document.getElementById("sourceDiv");
destination.appendChild(myDiv);
}
以下代码段来自父窗口
<div id='myDiv>
...
</div>
Under Internet Explorer 8, when I try to copy a Div from a window to a pop-up the getElementById method doesn't return DOM elements but plain elements. I can't call appendChild on those sort of items cause I get "Illegal argument" errors. What would be a solution of copying a div from a parrent window to a child pop-up window.
The code I've written so far works perfectly on Chrome, and Firefox, but not on IE.
this code is in the pop-up window:
this is called on when the pop-up is loading
<body onload="initialize();">
<div id='sourceDiv'></div>
</body>
function initialize(){
var source = window.opener.document;
var myDiv = source.getElementById("myDiv");
var destination = document.getElementById("sourceDiv");
destination.appendChild(myDiv);
}
the following snippet is from the parrent window
<div id='myDiv>
...
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不在 jQuery 中这样做呢? jQuery 被设计为独立于浏览器。
jQuery 代码将是这样的一行:
好的,我刚刚尝试了一个测试项目,并且此代码有效:
您需要确保在调用函数时加载文档。
Why dont you do this in jQuery? jQuery is designed to be browser independent.
jQuery code would be one line like so:
Ok I've just tried a test project and this code works:
You need to make sure the document is loaded when you call your function.