When a webview interface is invisible, such as it is pushed into the background, the screen is locked, or it switches into the next page via pushwindow, the event of page being pushed into the background (pause
) will be triggered.
Note:
- For the clients above version 10.0.15, the container newly adds the
pagePause
andappPause
events for the business to distinguish which case has triggeredpause
.- Page being pushed into background (
pause
) = client invisible due to being pushed into background (appPause
) + window invisible due to being siwtched to bottom (pagePause
).- Since the Android system cannot distinguish whether the native
resume
andpause
event are caused by pushed background or page switch, thepageResume
andpagePause
event are called back through the JSAPI calling record, and therefore only applicable to the mutual switch among windows in the same session. The method that startApp and other clients directly switch pages is invalid, such aschooseImage
.
Use pause interface
document.addEventListener('pause', function(e) {
alert("pause");
}, false);
Code sample
The following code sample shows the alert that pops up after the user leave the current page:
<h1>Please click the button to open a new window </h1>
<a href="javascript:void(0)" class="btn J_new_window">New window opens the current page</a>
<script>
function ready(callback) {
// Call the interface directly if JSBridge has been injected
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Monitor the injected events if JSBridge hasn't been injected
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>