0

I am trying to use the "window.open" method to open a URL in a new window. This is my code and it is not working, it keeps opening the URL in the same tab.

Let me know if there is anything I am doing wrong.

function checkVersion() {
    var msg = "";
    var ver = getInternetExplorerVersion();

    if (ver > -1) {
        if (ver >= 8.0)
            msg = "You're using a recent copy of Internet Explorer."
        else
            msg = "You should upgrade your copy of Internet Explorer.";

    }
    if (msg != "") {
        alert(msg);
        window.open('http://windows.microsoft.com/en-us/internet-explorer/download-ie', '_blank');
        window.focus();
    }
venerik
  • 5,766
  • 2
  • 33
  • 43
Paul T. Rykiel
  • 1,177
  • 6
  • 26
  • 48
  • You don't really get to force this upon the user. Browsers are free to prevent you from spawning popups. – user229044 Nov 12 '13 at 22:09
  • yes, I read that too. I just thought I would see if there is something I can do. Thanks – Paul T. Rykiel Nov 12 '13 at 22:10
  • I tested the code, it works fine on my machine. Can you do a view source and see if any old code is being cached? – SRay Nov 12 '13 at 22:11
  • as an end user, I would hate a website that did that to me... not only the pop-up bit, but also the fact that you're notifying me of what version of IE I'm running (not that I use the God-Forsaken IE browser). – Chase Florell Nov 12 '13 at 22:17

1 Answers1

1

To open a window in a new tab you can provide some height \ width specs to open in a new window and not a tab.

Here is a related stack overflow question. JavaScript open in a new window, not tab

EDIT: Sample.

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>

    <script type="text/javascript">

        function openTab() {
            window.open('http://stackoverflow.com', '_blank');
        }

        function openWindow() {
            window.open('http://stackoverflow.com', '_blank', 'height=200');
        }


    </script>

</head>
<body>
    <button onclick="openTab()">Open Tab</button>&nbsp;
    <button onclick="openWindow()">Open Window</button>
</body>
</html>
Community
  • 1
  • 1
Nico
  • 12,493
  • 5
  • 42
  • 62
  • You saw that that question was from 2009 and that the answers don't apply to modern browsers anymore, right? – Steve Nov 12 '13 at 22:12
  • @Steve have you tried this on modern browsers? This works just fine. I have posted an edit test script that works on Safari, Chrome, IE and FF. – Nico Nov 12 '13 at 22:20
  • Thank Nico, I will try. This is just a nice to have for our client. Best regards, – Paul T. Rykiel Nov 12 '13 at 22:25