![](/img/trans.png)
[英]Beforeunload is not working to redirect user to another page, how can I redirect user to another page/url when he attempts to close a window/tab?
[英]Is is possible to redirect a page to another url when i click on to the close tab or close a browser window?
當用戶嘗試關閉瀏覽器窗口時,我試圖將頁面重定向到另一個URL。
可以重定向而不顯示任何消息或彈出窗口嗎?
提前致謝
通過處理“ onbeforeclose”和/或“ onclose” JavaScript事件是很有可能的,但這不是一個好習慣,因為最終用戶不喜歡在關閉瀏覽器窗口時重定向到新頁面。
如果要實現它,則只需處理這些事件,然后在事件處理程序中運行自定義代碼...
您可以按照以下方式進行操作:
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit() {
window.open("http://www.google.com","GoogleWindow");
return "Do you want to go to google?";
}
</script>
如wanjarisushil所述 ,這不是一個好方法。
window.onbeforeunload = function(){
window.open("http://www.google.com","newwindow");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.