SCRIPT87: Invalid argument in IE 9, ASP.NET C#

2020-08-10 08:28发布

问题:

This is working in all other browsers except IE. I am building a link in the code behind in c#:

string link = <a onclick=\"Myfunction('" + Server.UrlEncode(mystring) + "');\" href=\"javascript:void(0);\">Open Pop Up Window</a>

This is my javascript function:

 function Myfunction(pMyString) {
        CloseWindow();

        var url = "DomainPath/MyPage.aspx?Site=" + pMyString;
        win = window.open(url, "Manage Domain", 'toolbar=no,location=no,status=no,directories=no,scrollbars=yes,resizable=no,width='+700+',height='+500);
    }

If the function is added to an onclick method in the aspx page, it works in IE. It seems to be only when I am building the link dynamically in the code behind. It will not accept any values as a parameter, and IE always outputs the error: SCRIPT87: Invalid argument with a line number to my function, however I am unable to debug. Have a missed something?

Here is the html output:

<td><a onclick="Myfunction('urlformyexample.com');" href="javascript:void(0);">Open Pop Up Window</a></td>

回答1:

IE9 debugger works and fails on your window.open command.

IE doesn't like the space in the windowName argument – "Manage Domain".

Remove any spaces, hyphens, and underscores (unless you want _blank) and try again.