How do I use window.open and window.close together

0

I want when a person presses the shift key a tab opens and the previous one closes but I can not.

<script>
    function keyCode(event) {
        var x = event.keyCode;
        var y = event.keyCode;
        if (x == 16) {  // 16 is the Shift key

           window.open('https://google.com.br' ,  '_blank')

           Window.close();
        }
    }
</script>   

But it only opens and does not close the previous one.

    
asked by anonymous 20.04.2017 / 17:43

1 answer

0

When you open the window, focus shifts to it, and the close () method is ignored.

Place this code in the window that was opened (child):

 window.opener.close();

This will close the window that opened it (mother).

    
20.04.2017 / 18:12