Sunday, December 21, 2008

Javascript:Window.Open Invalid Argument Error IE

Internet Explorer (IE) starts giving Javascript error when I tried to open Pop-up Dialog, Which works perfect with Fire Fox and Chrome.


So If you are getting javascript error in IE on doing Javascript:Window.Open

Javascript Error: Invalid Argument or Syntax Error 
Example: (In Asp.net Code Behind)
string url = "MyTestURL?qsTestId=" + TestId;

string winFeatures = "toolbar=no,status=no,menubar=no,height=400,width=400";

string winPoPUpScript = string.Format("javascript:window.open('{0}', 'My Test Popup', '{1}');", url, winFeatures);

lnkCounter.Attributes.Add("onclick", winPoPUpScript);

Opening Window.open with javascript works perfectly with Firefox and Chrome, but will give error with IE.

Solution (Quick Fix): 
You need to remove spaces from 2nd Argument of Javascript Function Window.open() to make it work with IE.   If your second argument of Window.Open contains spaces than you may receive javascript errors like Invalid Argument or Syntax Error. 

To Fix the above code we need remove spaces from 2nd argument of Window.open
Example: (In Asp.net Code Behind)
string url = "MyTestURL?qsTestId=" + TestId;

string winFeatures = "toolbar=no,status=no,menubar=no,height=400,width=400";

string winPoPUpScript = string.Format("javascript:window.open('{0}', 'MyTestPopup', '{1}');", url, winFeatures);

lnkCounter.Attributes.Add("onclick", winPoPUpScript);

1 comment:

Anonymous said...

Great post. Thanks for providing the detail lacking from IE's error message.

Most Recent Post

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape