2016-06-14 46 views
1

我曾嘗試將自定義消息返回給onbeforeunload確認框,但默認消息沒有改變我發送的內容。window.onbeforeunload自定義消息沒有設置返回消息。它總是顯示默認消息

window.onbeforeunload = function (event) { 
 
     event.preventDefault(); 
 
     return 'You are leaving this page. Please confirm or data will be lost'; 
 
};

這種變化根據MDN's browser compatibility chart for this event在Firefox 46.0.1工作 enter image description hereenter image description here

+0

哪個瀏覽器/版本?對於舊的IE瀏覽器,你需要'window.event.returnValue ='valueYouTypicallyReturn' –

+0

你期望發生什麼? – Gabs00

+0

@JuanMendes,我正在使用Chrome 51.0.2704 –

回答

3

,自定義文本支持已經從Chrome和Firefox的新版本中刪除。如果您使用的是FF> = 44.0或Chrome> = 51.0,則會獲得默認的窗口關閉文本,而不是您自己的文本。

+0

我剛剛在Ubuntu上使用Firefox 47.0嘗試了此操作,並且我收到了默認文本而不是您的文本。 (我沒有老版本的Firefox來測試) –

+0

啊,所以它是平臺特定的?有趣的是,我不會期望這一點。 –