The pause event is triggered when a WebView is no longer visible. This can happen when the page is sent to the background, the screen is locked, or you use pushwindow to navigate to a new page.
In client versions 10.0.15 and later, the container includes the
pagePauseandappPauseevents. These events specify why thepauseevent was triggered. TheappPauseevent occurs when the client is sent to the background, and thepagePauseevent occurs when the window is pushed to the bottom of the stack.The Android system cannot determine if a native
resumeorpauseevent is caused by the app being sent to the background or by a page switch. Because of this, thepageResumeandpagePauseevents use a callback based on JavaScriptAPI call records. This method only works for switching between windows in the same session. It does not work forstartAppor other client-side page switching methods, such aschooseImage.
Using the pause interface
document.addEventListener('pause', function(e) {
alert("pause");
}, false);Code example
The following example displays a warning when you leave the current page.
<h1>Click the button to open a new window</h1>
<a href="javascript:void(0)" class="btn J_new_window">Open current page in a new window</a>
<script>
function ready(callback) {
// If jsbridge is already injected, call it directly.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// If not, listen for the injection event.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('.J_new_window').addEventListener('click', function() {
AlipayJSBridge.call('pushWindow', {
url: location.pathname,
});
});
document.addEventListener('pause', function(e) {
alert('paused');
}, false);
});
</script>