在 IE 中插入脚本和 iframe 标签

发布于 2024-11-29 06:40:32 字数 756 浏览 0 评论 0原文

我想在打开的窗口中编写脚本和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铃予 2024-12-06 06:40:32

嗯,这很简单,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

浅紫色的梦幻 2024-12-06 06:40:32
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();
     }
 }
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();
     }
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文