简体   繁体   中英

How to open new window browser when user click close tab?

I tried this code to open new window browser when user click close tab but it doesn't work

<script>

window.onbeforeunload = function(e) {
    window.open("http://google.com");
window.stop();
};

</script>

So, can you give me any way to do that ?

window.addEventListener("beforeunload", function (e) {
  window.open('http://google.com','new','width=600,height=400,toolbar=1')

});

Guess that's the way.

Notice that most of browsers block pop-up windows by default.

You cannot. Opening a popup in response to the window being closed is forbidden by the specification :

An algorithm is allowed to show a popup if any of the following conditions is true:

The task in which the algorithm is running is currently processing an activation behavior whose click event was trusted.

The task in which the algorithm is running is currently running the event listener for a trusted event whose type is in the following list:

  • change
  • click
  • dblclick
  • mouseup
  • reset
  • submit

The task in which the algorithm is running was queued by an algorithm that was allowed to show a popup, and the chain of such algorithms started within a user-agent defined timeframe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM