简体   繁体   English

打开带有动态javascript内容的新窗口

[英]Open new window with dynamic javascript content

Is it possible to open new window with javascript open() function for example, but the window should be empty, so no HTML file and paste content to that, where will be javascript? 例如,是否可以使用javascript open()函数打开新窗口,但是该窗口应该为空,因此没有HTML文件,也没有内容粘贴到其中,javascript将在哪里?

I knoww how to open new window, how to paste content there, how to paste styles there (it works) but I paste there and javascript not working in this opened window. 我知道如何打开新窗口,如何在其中粘贴内容,如何在其中粘贴样式(它可以工作),但是我在那粘贴并且javascript在此打开的窗口中不起作用。

What am I doing wrong? 我究竟做错了什么?

EDIT: function for opening window: 编辑:打开窗口的功能:

function openNewWindow( url ) {
    var OpenWindow = window.open('','_blank','width=1024,height=768,resizable=1');
    var content = document.getElementById('forSBWindow');

    OpenWindow.document.write('<html><head><title>New window</title><link rel="stylesheet" type="text/css" href="'+url+'style.css"><link rel="stylesheet" type="text/css" href="'+url+'ref/ref.css"><script type="text/javascript" src="'+url+'main.js"></script><script type="text/javascript" src="'+url+'ref/ref.js"></script></head><body>');
    OpenWindow.document.write( content.outerHTML );
    OpenWindow.document.write('</body></html>');
}

And in this new opened window I need for example click on something and call some javascript function from ref.js but it doesn't work 在这个新打开的窗口中,例如,我需要单击某些内容,然后从ref.js调用一些javascript函数,但是它不起作用

I am run through same kind of problem some months before. 几个月前,我遇到了同样的问题。 Following code worked for me: This should help you too. 以下代码为我工作:这也将为您提供帮助。

var OpenWindow = window.open('','New Window','width=1024,height=768,resizable=1');
var content = document.getElementById('forSBWindow');

OpenWindow.document.writeln('<html><head><title>New window</title><link rel="stylesheet" type="text/css" href="'+url+'style.css"><link rel="stylesheet" type="text/css" href="'+url+'ref/ref.css"><script type="text/javascript" src="'+url+'main.js"></script><script type="text/javascript" src="'+url+'ref/ref.js"></script></head><body>');
    OpenWindow.document.writeln( content.outerHTML );
    OpenWindow.document.writeln('</body></html>');
    OpenWindow.document.close()
$('OpenWindow.document').ready(function(e) {
                        setTimeout(onloadFunction,500);
                    });

function onloadFunction(){ /*code here*/ }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM