通过js打开新窗口时执行javascript(执行javascrip
我正在使用javascript打开一个新窗口云南快3006直播亚博全站 ,并将内容写入新窗口。内容的一部分是一个javascript文件,但是javascript不会在新窗口中执行。帮助吗?
open.html:
< script >
function winopen()
{
var ghtml ="< h1 > < / span> sasaasas < / h1 > 跨度>";
var gwin = window.open("","_ blank","location = no,width = 1000,height = 600");
if(gwin)
{gwin.document.open();
gwin.document.write(ghtml);
var oscript = gwin.document.createElement("script");
oscript.type ="text / javascript";
oscript.src ="open.js";
gwin.document.getElementsByTagName("head")[0] .appendChild(oscript);
//gwin.document.close();
}
}
winopen();
< / script >
open.js:
function init(){ alert(" winwin"); }
setTimeout(function(){init();}, 2000 );
解决方案
在您的代码中打开页面就执行js亚博集团 ,没有显示任何应触发脚本执行的内容。解决方案很简单:您应该将一些脚本作为元素“ body”或“ html”的子元素放置。另一种方法是将属性onload添加到元素中(例如,参见[^])。由于您没有显示所创建窗口的HTML内容打开页面就执行js,因此我不确定是否要尝试这样做。
-SA
老王 上一篇:珠海国家税务局税务分局的电话地址
下一篇:关于我的爱人的最美丽的诗