views:

11849

answers:

8

I have a site that has an IE8-only problem:

The code is:

var w = window.open(urlstring, wname, wfeatures, 'false');

The error is:

Message: Invalid argument.
Line: 419 Char: 5
Code: 0
URI: http://HOSTNAME/js_context.js

I have confirmed the line number of the code (the "Line" and "URI" are correct), and I understand in later versions of IE8, this is considered accurate.

I have checked all the incoming parameters in the call by dumping alerts, and they all look valid.

This problem does not happen on FF (probably 3) and IE7 when the popup-blocker is off.

(Interestingly, the IE7 popup-blocker creates the same error when it is on.)

UPDATE:

The problem appears to be in using assigning the result of window.open() when doing "var w". When I split the line into two statements it works in IE8.

UPDATE2:

Based on:

http://javascript.crockford.com/code.html

When a function is to be invoked immediately, the entire invocation expression should be wrapped in parens so that it is clear that the value being produced is the result of the function and not the function itself.

This is not exactly what is going on here, but I found that applying the principle solved the problem, in IE8's compatability mode.

var w = (window.open(urlstring, wname, wfeatures, false));
A: 

Try remove the last argument. Other than that, make sure urlstring, wname, and wfeatures exist.

Macha
+1  A: 

What does position four represent, the one that has 'false' as an value? Shouldn't that be false, (i.e. without quotes?). It's possible that earlier versions of IE would coerce the string to a boolean, but newer ones don't.

x0n
I removed the quotes, but it wasn't the source of the problem for IE8.
benc
A: 

http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx

Jose Vega
+5  A: 

the problem might be the wname, try using one of those shown in the link above, i quote:

Optional. String that specifies the name of the window. This name is used as the value for the TARGET attribute on a form or an anchor element.

  • _blank The sURL is loaded into a new, unnamed window.
  • _media The url is loaded in the Media Bar in Microsoft Internet Explorer 6. Microsoft Windows XP Service Pack 2 (SP2) and later. This feature is no longer supported. By default the url is loaded into a new browser window or tab.
  • _parent The sURL is loaded into the current frame's parent. If the frame has no parent, this value acts as the value _self.
  • _search Disabled in Windows Internet Explorer 7, see Security and Compatibility in Internet Explorer 7 for details. Otherwise, the sURL is opened in the browser's search pane in Internet Explorer 5 or later.
  • _self The current document is replaced with the specified sURL.
  • _top sURL replaces any framesets that may be loaded. If there are no framesets defined, this value acts as the value _self.

if using another wname, window.open won't execute...

That last statement isn't correct. You can also (a) specify the name of an existing frame to load the page in that frame, (b) specify the name of an existing "named window" to load the page there, or (c) specify a name which doesn't exist to create a "named window".
Ben Blank
I had the same problem except I wasn't setting the result of window.open to a variable. Had a page title in the wname variable. Changed it to '_blank' and it fixed the problem.
Derek White
A: 

I discovered the same problem and after reading the first answer that supposed the problem is caused by the window name, changed it : first to '_blank', which worked fine (both compatibility and regular view), then to the previous value, only minus the space in the value :) - also worked. IMO, the problem (or part of it) is caused by IE being unable to use a normal string value as the wname. Hope this helps if anybody runs into the same problem.

+12  A: 

This is an old posting but maybe still useful for someone.

I had the same error message. In the end the problem was an invalid name for the second argument, i.e., I had a line like:

window.open('/somefile.html', 'a window title', 'width=300');

The problem was 'a window title' and it worked fine with the following line:

window.open('/somefile.html', '', 'width=300');

In fact, reading carefully I realized that Microsoft does not support an actual name as second argument. When you look at the page linked to above, you see that Microsoft only allows the following arguments, IF using that argument at all:

_blank _media _parent _search _self _top

Stefan
this helped me out thx
MUG4N
I think I had neglected to check the Mozilla explanation of this function, because I (asker) was focused on IE8-only breakage.
benc
simply put: https://developer.mozilla.org/en/DOM/window.open -> "strWindowName does not specify the title of the new window."
benc
I also recently found that the message was caused by illegal characters "/" and "+" being passed into wname. FF3 does not seem to object. In this sense, I think only IE8 is being strict, but that is probably a good thing.
benc
+8  A: 

Don't use spaces in the 2nd argument.

prlafferty
So ridiculous that this is the reason :/
Alastair Pitts
A: 

@Stefan,

Thanks buddy. I removed spaces and it worked in IE8 too.

Vaibhav