在 IE 中插入脚本和 iframe 标签
我想在打开的窗口中编写脚本和 iframe 元素,这在 Firefox 和 Chrome 中工作正常,但在 IE 中不行。
我的代码如下:
var mywindow = window.open(url,'child',params);
mywindow.onload = writeToWindow;
function writeToWindow(){
var myScriptEle = document.createElement('script');
myScriptEle.type = "text/javascript";
myScriptEle.text = " some script";
var myIframe = document.createElement("IFRAME");
myIframe.id = "childwindow";
myIframe.name = "childwindowname";
myIframe.src = MyframeUrl;
if(mywindow){
mywindow.document.getElementsByTagName('body')[0].appendChild(myScriptEle);
mywindow.document.body.appendChild(myIframe);
}
}
我收到“不支持此类接口”错误
提前致谢,请告诉我是否有适用于 IE 的解决方法
I want to write script and iframe elements in the opened window, which works fine in Firefox and Chrome, but not in IE.
My code is below:
var mywindow = window.open(url,'child',params);
mywindow.onload = writeToWindow;
function writeToWindow(){
var myScriptEle = document.createElement('script');
myScriptEle.type = "text/javascript";
myScriptEle.text = " some script";
var myIframe = document.createElement("IFRAME");
myIframe.id = "childwindow";
myIframe.name = "childwindowname";
myIframe.src = MyframeUrl;
if(mywindow){
mywindow.document.getElementsByTagName('body')[0].appendChild(myScriptEle);
mywindow.document.body.appendChild(myIframe);
}
}
I'm getting "No such interface supported" errors
Thanks in advance, please let me know if there's any work around for IE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,这很简单,IE 中不支持 getElementsByTagName(或者它不支持它应该做的事情)!
对于这样的事情,你最好使用像 jQuery 这样的库。这将帮助您编写适用于所有浏览器的代码,并且不会花费您数小时的时间来弄清楚为什么某些内容在浏览器 x 或 y 中不起作用
Well it's quite easy, getElementsByTagName is not supported(well either that or it doesnt do what it should) in IE!
For things like this you're better off getting a library like jQuery. This will help you write code that will work on all browsers and won't cost you hours of your time figuring out why stuff doesn't work in browser x or y