JavaScript Invalid Argument in Internet Explorer Only
by Frank Kim on Aug.11, 2009, under JavaScript
Today I noticed one of my links were not working. This was only happening in Internet Explorer 8. Looking down at the status bar in the lower left corner I saw the message “Error on page.” Double-clicking on it popped up this window full of useless information.
A Google search for “internet explorer invalid argument” brought me to this page, Internet Explorer Sucks. Fortunately the author had run into this problem and figured out the solution.
It turns out In Internet Explorer, the second argument to the JavaScript window.open method, which is the windowName argument, can’t have spaces. My original link looked like this.
<a href="javascript:void(0);" onclick="window.open('popUp.jsp','Frank Kim betweenGo','menubar=0,toolbar=0,location=0,scrollbars=yes,width=400,height=175')">What's this?</a>
When I took out the spaces from the windowName argument the link worked. You would think Internet Explorer 8 would have fixed this issue by now, it doesn’t affect any other modern web browser.
Related posts:

August 18th, 2009 on 2:36 AM
A massive thank you for sharing this information. I had exactly the same problem. Firefox was fine but IE was doing what it is good at and stressing me out! Your solution worked perfectly.
I wonder if I could sue Bill Gates for loss of hair and a drinking habit….?
August 18th, 2009 on 2:42 PM
Thanks John. Your thank you comment is almost exactly the same as the thank you comment I left in the blog post I referenced, “Internet Explorer Sucks.”
September 21st, 2009 on 6:42 AM
Thank you so much!!! I have been pulling my hair for twenty minutes when I came across this page: I had a space in the name field of my new window. I would never thought of it. Thank you so much.
Li
September 21st, 2009 on 6:44 AM
You are quite welcome Li.
January 2nd, 2010 on 3:09 PM
Name can’t have – either. That was my problem.
Thanks for pointing me to the right direction!
January 19th, 2010 on 7:50 AM
Thanks. In addition to not allowing spaces, dashes are also not allowed.
January 19th, 2010 on 7:56 AM
Wow, not even dashes! Thanks for the info John.
March 10th, 2010 on 6:36 AM
Thanks! It worked just fine. God bless!
March 10th, 2010 on 9:13 PM
Thanks a ton for this info. Have been searching around for quite some time for a solution.
September 21st, 2010 on 6:16 AM
Thanks for all!
April 5th, 2011 on 12:20 AM
Thanks man, that helped a lot!!
April 18th, 2011 on 8:58 PM
Thanks a ton………. really got stuck with this… now working well.
April 29th, 2011 on 4:52 AM
The Stupid IE9 Continues with this issue,
thanks so much for your sharing
May 4th, 2011 on 12:58 PM
ie7 has the same issue. Funny thing is that lots of Government agencies still using it!
May 15th, 2011 on 9:05 PM
Thank you for this! Saved me the trouble of having to look further into the issue.
November 12th, 2011 on 10:29 PM
Do you know if you can put in some sort of character sequence to get the spaces if you want them?
November 13th, 2011 on 6:57 AM
Jared, try %20 in your URL for a space.
http://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20
November 29th, 2011 on 2:33 AM
Even i am getting the following
Line: 14
Character: 4
Code: 0
Error Message: Invalid argument.
in an external.js file.
Really struggling with the error.
this is that js file
function goExternalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName(“a”);
for (var i=0; i<anchors.length; i++)
{
var anchor = anchors[i];
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
please need response urgently
November 29th, 2011 on 1:46 PM
Hi Krithi,
Not sure what that error could be. Is it an IE only issue? Your code doesn’t have the window.open which was causing the problem I found in this post.
-Frank
November 29th, 2011 on 9:30 PM
yes it occurs only in IE.any other clue to check it.
November 30th, 2011 on 7:56 AM
Hi Krithi,
My other guess is that one of the URL’s on your page has a space in it. Try testing your function on a simple page with one anchor. Make the URL in the anchor have a space and see if you can reproduce the problem.
-Frank