2016-06-14 112 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

啊,所以它是平台特定的?有趣的是,我不会期望这一点。 –