2
votes

I'm seeing "Invalid Argument" in Internet Explorer with window.open using javascript. How will I fix it?

I'm getting "Invalid Argument" in line "var newwindow = window.open (url, 'Popup Demo', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);".

Here's my code:

<script type="text/javascript" language="javascript">
<!--

function popitup(url) {

    var w = 500;
    var h = 500;

    var left = (screen.width/2)-(w/2);
    var top = (screen.height/2)-(h/2);

    var newwindow = window.open (url, 'Popup Demo', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);

    if (window.focus) {
        newwindow.focus();
    }
    return false;
}

// -->
</script>
3
Why do you have the comment of "Don't render this script as text in Netscape 2 era browsers" there? Nobody uses Netscape 2 era browsers.Quentin

3 Answers

6
votes

Window names may not have spaces in IE. Change 'Popup Demo' to 'PopupDemo'

1
votes

According to https://developer.mozilla.org/en-US/docs/DOM/window.open, the second parameter, strWindowName, should not have any spaces in it. Since yours does, that might be the problem.

0
votes

I found one more case when IE and Edge display "Invalid argument" error during interaction with a child window. It happens on attempt to insert an element created in parent window document to child window document. All the other browsers work just fine.