[英]Open new window with dynamic javascript content
例如,是否可以使用javascript open()函數打開新窗口,但是該窗口應該為空,因此沒有HTML文件,也沒有內容粘貼到其中,javascript將在哪里?
我知道如何打開新窗口,如何在其中粘貼內容,如何在其中粘貼樣式(它可以工作),但是我在那粘貼並且javascript在此打開的窗口中不起作用。
我究竟做錯了什么?
編輯:打開窗口的功能:
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>');
}
在這個新打開的窗口中,例如,我需要單擊某些內容,然后從ref.js調用一些javascript函數,但是它不起作用
幾個月前,我遇到了同樣的問題。 以下代碼為我工作:這也將為您提供幫助。
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.