在IE中插入脚本和iframe标签
Insert script and iframe tag in IE
我想在打开的窗口中编写脚本和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);
}
}
我得到"No such interface supported"错误
提前感谢,请告诉我是否有任何工作围绕IE
这很容易,getElementsByTagName是不支持的(好,或者它不做什么它应该)在IE!
对于这样的事情,你最好使用jQuery之类的库。这将帮助你编写适用于所有浏览器的代码,而不会花费你几个小时的时间去弄清楚为什么某些东西在浏览器x或y中不起作用var mywindow = window.open(url,'child',params);
writeToWindow();
function writeToWindow(){
var content = '<script type="text/javascript">';
content += 'function updatePage(){ ';
content += 'var myiframe = document.createElement("IFRAME");';
content += 'myiframe.id = "myIframe";';
content += 'myiframe.name = "iframe_js";';
content += 'myiframe.className = "iframe_js";';
content += 'myiframe.src ="http://stackoverflow.com"';
content += '</script>';
if(mywindow){
mywindow.document.open();
mywindow.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'+content+'</head><body onload="updatePage()"><div></div></body></html>');
mywindow.document.close();
}
}
相关文章:
- iframe正在添加标签,需要删除它们
- 获取 iframe 内点击标签的父级
- 仅将元素附加到页面的正文标签,而不添加到iframe facebook、google+、twister
- 访问动态创建的iframe内容/元素,如文本框,来自JavaScript的标签
- 为什么我的 iframe 标签不起作用
- 谷歌浏览器的“新标签”iframe如何工作
- Iframe 不适用于表单中的标签
- 无法添加 Youtube iframe 标签
- fangating在facebook iframe标签使用任何其他PHP
- 通过iframe标签访问facebook并获得交叉原点错误
- 从Javascript中嵌套的iframe标签中删除垂直滚动条
- AngularJS{{}}占位符不能在Iframe标签中工作
- 如何从iframe标签中删除样式(不是在iframe内,而是在标签内)
- 在302重定向或嵌入/对象/iframe标签中的元素后获得flash src(跨域)
- 窗口.打开后不显示任何添加iframe标签
- 使用iframe标签在浏览器中查看文档文件
- 添加播放列表到iframe标签
- 在IE中插入脚本和iframe标签
- 当我在 iframe 中导航并且 URL 被更改时,如何在包含 iframe 标签的页面中获取 iframe 的 URL
- 用iframe标签显示网站的一部分