ie8 var w= window.open() - "Message: Invalid argument."

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).

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));

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' as it is not valid. It worked fine with the following line:

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

In fact, reading carefully I realized that Microsoft does not support a name as second argument. When you look at the official documentation page, you see that Microsoft only allows the following arguments, If using that argument at all:

  • _blank
  • _media
  • _parent
  • _search
  • _self
  • _top

IE is picky about the window name argument. It doesn't like spaces, dashes, or other punctuation.


When you call window.open in IE, the second argument (window name) has to be either one of the predefined target strings or a string, which has a form of a valid identifier in JavaScript.

So what works in Firefox: "Job Directory 9463460", does not work in Internet Exploder, and has to be replaced by: "Job_Directory_9463460" for example (no spaces, no minus signs, no dots, it has to be a valid identifier).


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...