Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts

    window.open, appending <script> not working in ie

    My page has a js function to open a new window with window.open. The new window needs to have a bunch of javascript on it, but ie8 refuses to allow it.

    With FF and every other browser I can set the innerHTML of the new window to include <script>...</script> tags, or append them using the DOM appendChild method after the new window opens to either the body or the head, no problem. The new window loads fine and all the scripts work.

    However, I tried all this in IE8 and I either get a "no such interface is supported" error, or the new window and the calling window both just freeze and I have to kill them with Task Manager.

    Is there any way to include <script> tags in a new window with ie8? PLEASE help!

    Here's an example of what I'm trying to do:

    Code:
    function openwindow()
    {
    var ih=''
    ih += '<!doctype html><html><head>'
    ih += '<meta charset="UTF-8" />'
    ih += '<script type="text/javascript" src="script1.js"></script>'
    ih += '<script type="text/javascript" src="script2.js"></script>'
    ih += '<script type="text/javascript" src="script3.js"></script>'
    ih += '</head>'
    
    ih += '<body>'
    ih += '<h1>test</h1>'
    ih += 'yay'
    ih += '</body>'
    ih += '</html>'
    
    mywin = window.open('','','width=500px, height=500px')
    mywin.document.open()
    mywin.document.writeln(ih)
    mywin.document.close()
    }
    I also tried something like this:

    Code:
    function openwindow()
    {
    var ih=''
    ih += '<!doctype html><html><head>'
    ih += '<meta charset="UTF-8" />'
    ih += '</head>'
    
    ih += '<body>'
    ih += '<h1>test</h1>'
    ih += 'yay'
    ih += '</body>'
    ih += '</html>'
    
    mywin = window.open('','','width=500px, height=500px')
    mywin.document.open()
    mywin.document.writeln(ih)
    mywin.document.close()
    
    appendscripts(mywin)
    }
    
    function appendscripts(mywin)
    {
      var sarr = ['script1.js', 'script2.js', 'script3.js']
    
      for(var x=0;x<sarr.length;sarr++)
      {
        var s = document.createElement('script')
        s.type='text/javascript'
        mywin.document.getElementsByTagName('head')[0].appendChild(s)
        mywin.src = sarr[x]
      }
    }
    but that didn't work in ie either.
    Last edited by Raphael; 08-29-2012 at 05:58 AM.

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts
    I was able to fix it in ie by having ie-specific code. Basically file1 uses window.open to open the new window, and then using an inline script, the opened window appends the <script>'s to itself.

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    145
    Thanks
    0
    Thanked 26 Times in 26 Posts
    Hi Raphael,

    i was curious, as i'm still on a learning curve with javascript, what is the purpose of passing a script to a new window...i'm guessing based on some type of event rather than just linking to a new page with a specific javascript?

    thanks


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •