Reputation: 33
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 ?
Upvotes: 1
Views: 2066
Reputation: 943193
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.
Upvotes: 1
Reputation: 331
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.
Upvotes: 1