簡體   English   中英

我需要在瀏覽器關閉時彈出確認窗口。我正在使用onbeforeunload事件,但無法在Firefox中使用,並且還希望限制頁面刷新時的彈出窗口

[英]I need a confirmation pop up on browser close.I am using onbeforeunload event but not working in Firefox also want to restrict pop up on page refresh

我需要在瀏覽器關閉時彈出確認信息。 我使用onbeforeunload事件,但在Firefox中不起作用,每當刷新頁面時,我都會限制彈出窗口。

window.onbeforeunload = DetectBrowserExit;

function DetectBrowserExit() {
return 'Are you sure to exit';`enter code here`
}

並非所有瀏覽器都支持此功能,並且隨着時間的流逝,瀏覽器將其支持降到最低(例如,刪除了自定義文本支持)。 原因是它被垃圾郵件之類的網站使用,從而阻止了您的瀏覽。

您可以在此處查看完整的詳細信息:

https://developer.mozilla.org/zh-CN/docs/Web/API/WindowEventHandlers/onbeforeunload

還要檢查該頁面中的“瀏覽器兼容性”部分。 我絕對建議不要依賴該事件,並提出更適合您的網站的替代方法。

特別是關於firefox的信息,請參閱我上面共享的鏈接中的以下說明:

Note also that various mobile browsers ignore the result of the event (that is, they do not ask the user for confirmation). Firefox has a hidden preference in about:config to do the same. In essence this means the user always confirms that the document may be unloaded.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM