如何使用javascript在子窗口中添加脚本文件? [英] How to add script files in child window using javascript?

查看:155
本文介绍了如何使用javascript在子窗口中添加脚本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript在子窗口中添加脚本文件?

How to add script files in child window using javascript?

请考虑以下代码:

myWindow = window.open("", "", 'width=650,height=700,menubar=yes,resizable=yes,scrollbars=yes');
myWindow.focus();
myWindow.document.write('<script src="'+App.data.assets_url+'\/javascript\/jquery.js"><\/script>');

以上代码在IE中无法正常运行。它显示空白(子)窗口,但在chrome中它可以正常工作。它显示了子窗口的所有内容。

Above code doesn't work properly in IE. It shows blank (child) window, but in chrome it works properly. It shows all the content of the child window.

在Mozilla中,由于上面的 myWindow.document.write 行浏览器的打印选项。

In Mozilla it's not working properly too because of above myWindow.document.write line browser's print option.

推荐答案

基本上:

var win, doc;

win = window.open('', 'dialog', opts);
doc = win.document;

doc.write(
    "<html><head>"
    + "<script type='text/javascript' src='path/to/your/script.js'></script>"
    + "<script type='text/javascript'>"
    + "/* this is inline script inserted by JavaScript, below is a function converted to it's string representation */"
    + someFuncInVariable.toString()
    + "</script>"
    + "</head><body>"
    + "</body></html>"
);
doc.close();

这篇关于如何使用javascript在子窗口中添加脚本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆