简体   繁体   中英

Open new popup if tab is close event

i just want to open a new popup if the browserwindow is closed. i have following code, but it doesnt seem to work

<script type="text/javascript">
    window.onbeforeunload = function () {
         window.open("http://www.w3schools.com"); 
    }
</script>

thanks

You're looking for the onUnload event, not onBeforeUnload .

onBeforeUnload is expected to return a string which is used in an automatic confirm window. Word of warning, most pop up blockers will ignore calls to window.open executed from an onUnload event.

See the mdc documentation here for onUnload and here for onBeforeUnload .

The function you set as window.onbeforeunload must return a string that will be shown to the user in a messagebox.

window.onbeforeunload = function () {
     window.open("http://www.w3schools.com"); 
return "something";
}

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