All Products
Search
Document Center

Pause

Last Updated: Mar 24, 2021

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 and appPause events for the business to distinguish which case has triggered pause.
  • 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 and pause event are caused by pushed background or page switch, the pageResume and pagePause 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 as chooseImage.

Use pause interface

 
  1. document.addEventListener('pause', function(e) {
  2. alert("pause");
  3. }, false);

Code sample

The following code sample shows the alert that pops up after the user leave the current page:

 
  1. <h1>Please click the button to open a new window </h1>
  2. <a href="javascript:void(0)" class="btn J_new_window">New window opens the current page</a>
  3. <script>
  4. function ready(callback) {
  5. // Call the interface directly if JSBridge has been injected
  6. if (window.AlipayJSBridge) {
  7. callback && callback();
  8. } else {
  9. // Monitor the injected events if JSBridge hasn't been injected
  10. document.addEventListener('AlipayJSBridgeReady', callback, false);
  11. }
  12. }
  13. ready(function() {
  14. document.querySelector('.J_new_window').addEventListener('click', function() {
  15. AlipayJSBridge.call('pushWindow', {
  16. url: location.pathname,
  17. });
  18. });
  19. document.addEventListener('pause', function(e) {
  20. alert('paused');
  21. }, false);
  22. });
  23. </script>