views:

189

answers:

2

Hi all,

I am using the prototype JavaScript library to read the contents of a text area (which is often the complete mark-up for another HTML page), create a new window and then set the new window content to be that same mark-up, like so:

var htmlContent = $("msHTML").value;
var win = window.open("preview.cfm", "Preview HTML", "left=20,top=20,width=500,height=500,toolbar=0,resizable=1,scrollbars=1");
win.document.write(htmlContent); //TODO - throwing an error in IE 7 - Error Invalid Argument
win.document.close();

This works just fine in Firefox but as mentioned in the comment, it's giving an Illegal Argument exception in IE7.

Can anyone help?

I couldn't find anything in the prototype library that might get around browser differences when setting document content. I know there might be another windowing library built on prototype that might work, but that seems like overkill for this issue I think.

Thanks in advance!

+1  A: 

Remove URL and Title from window.open() - it's a security related issue. You don't need to specify URL anyway since your overwriting window's content on the next line of your code.

This works:

var win = window.open('', '', 'left=20,top=20,' +
         'width=500,height=500,toolbar=0,resizable=1,scrollbars=1');

win.document.write($("msHTML").value);
Koistya Navin
+2  A: 

The 2nd parameter for

window.open(url, name, features);

"name" in IE, MUST NOT CONTAIN SPACES. (affects all versions of IE)

//works
window.open('page.html', 'mypage', '');

//FAILS in IE
window.open('page.html', 'my page', '');
scunliffe