我开发了以下代码:
window.onbeforeunload = function(event) {
var message = onLeaveMessage;
event = event || window.event;
if (event) {
// This is for IE
event.returnValue = message;
}
// This is for all other browsers
return message;
}
但是,此代码在IPad / iPhone中不起作用。经过简短的研究,我发现必须使用卸载或页面隐藏,然后提出了以下解决方案:
var eventName = isIphoneOrIpad() ? "pagehide" : "beforeunload";
window.addEventListener(eventName, function(event) {
var message = onLeaveMessage;
event = event || window.event;
if (event) {
// This is for IE
event.returnValue = message;
}
// This is for all other browsers
return message;
}
);
最后一个代码仍适用于桌面平台,但是不适用于iPad和iPhone。
有什么主意吗?