113

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));
Zanon
  • 29,231
  • 20
  • 113
  • 126
benc
  • 1,381
  • 5
  • 31
  • 39
  • I had the same problem, and David's post is the best answer. Thank you for your post and for David's help. – Ervin Sep 23 '10 at 09:29

14 Answers14

251

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
John
  • 29,788
  • 18
  • 89
  • 130
  • 1
    I think I had neglected to check the Mozilla explanation of this function, because I (asker) was focused on IE8-only breakage. – benc Sep 23 '10 at 16:27
  • 2
    simply put: https://developer.mozilla.org/en/DOM/window.open -> "strWindowName does not specify the title of the new window." – benc Sep 23 '10 at 16:28
  • 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 Sep 27 '10 at 16:28
  • 33
    I also had this error in IE when my windows name had a dash "-" in the name such as "my-windowname", IE quality never ceases to amaze me. – Matt Palmerlee Jul 27 '11 at 06:09
  • Really helpful info thanks I think space is not allowed underscore works fine – ppant Sep 08 '11 at 03:45
  • 1
    The MSDN documentation page you linked to states "Optional. String that specifies the name of the window. ", that sounds to me like you should be able to any keyword besides the the arguments you listed above. – James McMahon Dec 13 '11 at 19:36
  • thanks for this! I wasted only 15 minutes on this error until I found this helpful post just for the record, I think it used to work in IE7 using arbitrary names, but it got changed in IE8 to the more strict implimentation. It still happens in IE9 so you better just stick to the predefined window names. – Myke Black Feb 06 '12 at 20:35
  • 3
    It works in IE8 with names like ImageDisplay1234 but does not work with Image-Display-1234 – boatcoder Feb 25 '12 at 19:58
  • @ Matt, actually, IE does a better job here catching those who didn't read the docs, whereas most other browsers just let it pass. As much as I am not a fan of IE, this seems to be in its favor. – Dmitry Mar 10 '12 at 04:02
  • 1
    The second parameter specifies TARGET attribute, which can be an arbitrary string too: http://msdn.microsoft.com/en-us/library/ms534659(v=vs.85).aspx. – niaher Aug 22 '12 at 03:31
  • Thank you very much! Still relevant in 2014 unfortunately. – wpp May 09 '14 at 13:07
  • 1
    This answer is actually **incorrect**. The format of the method is `window.open(url, [name], [features], [ieOnlyNonSpec_Replace]);` The issue is with the optional `name` parameter. Various versions of IE have bugs where **spaces** or **dashes** in the name cause the window to not open. (Sadly I've just discovered an IE8 issue in *some* setups where a **blank** name (if supplied) causes issues too (extreme corner case with remote terminal setup)) – scunliffe Mar 17 '15 at 16:53
78

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

Charlie
  • 8,530
  • 2
  • 55
  • 53
prlafferty
  • 1
  • 2
  • 2
16

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

T.S.
  • 18,195
  • 11
  • 58
  • 78
Mr. Napik
  • 5,499
  • 3
  • 24
  • 18
8

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

David
  • 34,223
  • 3
  • 62
  • 80
  • 5
    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 May 29 '09 at 21:59
  • 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 Jun 24 '09 at 18:48
  • What I narrowed it down to was don't include - or . When I got rid of the punctuation Image-Display-1234 -> ImageDisplay1234 then all was well. – boatcoder Feb 25 '12 at 19:56
  • 1
    To support Ben's argument, this is what MSDN says about window.open's 2nd parameter: "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." And here is the TARGET attribute doc: http://msdn.microsoft.com/en-us/library/ms534659(v=vs.85).aspx. It clearly says that target can be an arbitrary string and not just the values listed in this answer. – niaher Aug 22 '12 at 03:30
5

Actually a name can be used however it cannot have spaces so window.open("../myPage","MyWindows",...) should work with no problem (window.open).

CSchulz
  • 10,882
  • 11
  • 60
  • 114
oliver
  • 1
  • 1
  • 1
4

I also meet this issue while I used the following code:

window.open('test.html','Window title','width=1200,height=800,scrollbars=yes');

but when I delete the blank space of the "Window title" the below code is working:

window.open('test.html','Windowtitle','width=1200,height=800,scrollbars=yes');
Anand
  • 5,323
  • 5
  • 44
  • 58
Raymond
  • 1
  • 2
2

Hi using the following code its working...

onclick="window.open('privacy_policy.php','','width=1200,height=800,scrollbars=yes');

Previously i Entered like

onclick="window.open('privacy_policy.php','Window title','width=1200,height=800,scrollbars=yes');

Means Microsoft does not allow you to enter window name it should be blank in window.open function...

Thanks, Nilesh Pangul

CSchulz
  • 10,882
  • 11
  • 60
  • 114
2

For me the issue was with a dash "-" in the window name field. I removed the dashes and IE does not error out and in fact opens the window.

iohans
  • 838
  • 1
  • 7
  • 15
1

The answers here are correct in that IE does not support spaces when setting the title in window.open(), none seem to offer a workaround.

I removed the title from my window.open call (you can use null or ''), and hten added the following to the page being opened:

<script>document.title = 'My new title';</script>

Not ideal by any means, but this will allow you to set the title to whatever you want in all browsers.

MrGlass
  • 9,094
  • 17
  • 64
  • 89
1

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
  • 51,312
  • 7
  • 89
  • 111
0

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.

0

It seems when even using a "valid" custom window name (not _blank, etc.) using window.open to launch a new window, there is still issues. It works fine the first time you click the link, but if you click it again (with the first launched window still up) you receive an "Error: No such interface supported" script debug.

Vince
  • 11
  • 2
0

If you want use the name of new window etc posting a form to this window, then the solution, that working in IE, FF, Chrome:

  var ret = window.open("", "_blank");
  ret.name = "NewFormName";

  var myForm = document.createElement("form");
  myForm.method="post";
  myForm.action = "xyz.php";
  myForm.target = "NewFormName";

      ...
0

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

Macha
  • 14,366
  • 14
  • 57
  • 69