[英]Javascript code inside beforeunload callback not working in Safari
I have added code to change web page color on beforeunload
event: 我添加了代码来更改beforeunload
事件上的网页颜色:
window.onbeforeunload = function (){
$('.navbar-collapse').css({background: 'blue'});
console.log("Hello unload");
return null;
}
Any idea? 任何想法?
window.onbeforenload
is "magic" in the sense that it is special and more and more browsers are restricting what it can do. window.onbeforenload
具有特殊意义,并且越来越多的浏览器限制了它的功能,因此它是“神奇的”。
Some browsers will let you display a custom message, other browers are free to ignore this event entirely. 一些浏览器将允许您显示自定义消息,其他浏览器则可以完全忽略此事件。
In short: Don't try to do anything but return a null or non-null value and hope for the best. 简而言之:除了返回null值或非null值并希望获得最佳结果外,不要尝试做任何事情。 It is out of your hands. 它不在您手中。
You might want to see this answer too: window.onbeforeunload and window.onunload is not working in Firefox , Safari , Opera? 您可能也想看看这个答案: window.onbeforeunload和window.onunload在Firefox,Safari,Opera中不起作用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.