Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2012, 03:47 AM   PM User | #1
Raphael
New Coder

 
Join Date: Mar 2009
Posts: 70
Thanks: 3
Thanked 3 Times in 3 Posts
Raphael is an unknown quantity at this point
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 04:58 AM..
Raphael is offline   Reply With Quote
Old 08-29-2012, 04:37 PM   PM User | #2
Raphael
New Coder

 
Join Date: Mar 2009
Posts: 70
Thanks: 3
Thanked 3 Times in 3 Posts
Raphael is an unknown quantity at this point
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.
Raphael is offline   Reply With Quote
Old 08-29-2012, 04:57 PM   PM User | #3
Brandnew
New Coder

 
Join Date: Aug 2012
Posts: 50
Thanks: 0
Thanked 11 Times in 11 Posts
Brandnew is an unknown quantity at this point
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
Brandnew is offline   Reply With Quote
Reply

Bookmarks

Tags
ie8, script, window.open

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:35 AM.


Advertisement
Log in to turn off these ads.