0

I can open a new tab with content using window.open() like this:

http://jsfiddle.net/8dXvt/

But how can I load a javascript file (script tag with src attribute) in the new tab? I want the resulting html of the tab to look like this:

<html>
    <head></head>
    <body>
      <script src="http://www.example.com/example.js"></script>
      <p>Your content here</p>
    </body>
</html>

To add the code directly into the "toNewWindow" div tag does not work because it of course immediately loads the js file in the original tab..

Thanks!

clic
  • 365
  • 1
  • 13
  • I dont really think its a duplicate , because I need a solution for an empty tab which I created e.g. via window.open(..) – clic Dec 09 '17 at 15:47
  • I found an easy solution now: var w = window.open(), theDoc = w.document, theScript = document.createElement('script'); theScript.type = "text/javascript"; theScript.src = "http://www.example.com/example.js"; theDoc.body.appendChild(theScript); – clic Mar 16 '18 at 19:32

0 Answers0