0

I'm not even sure if this is possible, but can you open a new tab in a browser and close the current one using Javascript/JQuery?

I've got the following Javascript that operates a modal popup:

<!--//**********************************
    // Test modal popup
    //**********************************  -->
<script type="text/javascript">
    //Total out of range dialog
    $(function () {
        $("#dialog").dialog({
            modal: true,
        //    autoOpen: false,
        width: 570,
        buttons: {
            "Ok": function () { $(this).dialog("close"); },
            "Cancel": function () {
                $(this).dialog("close");
                window.open('http://www.example.com/', '_blank');
            }
        }

        });
    });

What I'd like to do is close the current tab so that only the new tab is open. It doesn't seem like it's possible, but I figured I'd ask the experts here just to be sure.

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117
  • 1
    possible duplicate of [How to close current tab in a browser window?](http://stackoverflow.com/questions/2076299/how-to-close-current-tab-in-a-browser-window) – Hacketo Sep 03 '15 at 14:26
  • The first comment of the accepted answer is useful – Hacketo Sep 03 '15 at 14:27
  • Window.Close() will close the new window. If you use it before it opens the new window, it will close the current window before the new window opens. – Johnny Bones Sep 03 '15 at 14:29
  • from [docs](https://developer.mozilla.org/en-US/docs/Web/API/Window/close) `This method is only allowed to be called for windows that were opened by a script using the window.open() method` – Hacketo Sep 03 '15 at 14:30

0 Answers0