All Products
Search
Document Center

Mobile Platform as a Service:Pause

Last Updated:Jan 26, 2026

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.

Note
  • In client versions 10.0.15 and later, the container includes the pagePause and appPause events. These events specify why the pause event was triggered. The appPause event occurs when the client is sent to the background, and the pagePause event occurs when the window is pushed to the bottom of the stack.

  • The Android system cannot determine if a native resume or pause event is caused by the app being sent to the background or by a page switch. Because of this, the pageResume and pagePause events use a callback based on JavaScriptAPI call records. This method only works for switching between windows in the same session. It does not work for startApp or other client-side page switching methods, such as chooseImage.

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>