How to add script files in child window using javascript?
Consider the following code:
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>');
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.
In Mozilla it's not working properly too because of above myWindow.document.write line browser's print option.
Basically:
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();
Supposing you don't have domain crossing, you may simply do this (using jquery) :
$(childwindow.document.body).append('<script src="..."></script>');
But a more detailed question might enable more on topic answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With