2

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>
1
  • 1
    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
    Nov 19, 2012 at 15:15

3 Answers 3

6

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

1

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.