我有一个Paypal付款链接页面,我的页面使用location.href将用户重定向到付款页面。但是,如果他用浏览器停止按钮中止页面,我想显示带有链接的消息。如何获取页面加载停止事件?
您可以使用document.onstop
在用户中止加载文档时发生。如果发生onstop事件,则不会在文档上触发onload事件。
document.onstop = OnStopDocument;
function OnStopDocument () {
alert ("The loading of the document has been aborted.");
}
function OnLoadDocument () {
alert ("The document has been loaded.");
}
<body onload="OnLoadDocument ()">
Loading the document
</body>