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?
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.
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
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*/ }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.