All Products
Search
Document Center

Mobile Platform as a Service:Exit the current app

Last Updated:Feb 07, 2021

You can call this operation to exit the current stack-top app.

exitApp API usage instruction

  1. AlipayJSBridge.call('exitApp');

Code sample

  • Exit the current page:
  1. <h1>Click to exit the current page.</h1>
  2. <a href="#" class="btn J_demo">Execute</a>
  3. <script>
  4. function ready(callback) {
  5. // Call JS Bridge if it has been injected.
  6. if (window.AlipayJSBridge) {
  7. callback && callback();
  8. } else {
  9. // Listen to the injection event if it has not been injected.
  10. document.addEventListener('AlipayJSBridgeReady', callback, false);
  11. }
  12. }
  13. ready(function() {
  14. document.querySelector('.J_demo').addEventListener('click', function() {
  15. AlipayJSBridge.call('exitApp');
  16. });
  17. });
  18. </script>
  • Page jumping instance:
  1. <h1>Click the following button to jump between pages.</h1>
  2. <h3></h3>
  3. <a href="javascript:void(0)" class="btn new">New current page</a>
  4. <a href="javascript:void(0)" class="btn back">Return by 1 level.</a>
  5. <a href="javascript:void(0)" class="btn popTo">Return by 2 levels using popTo.</a>
  6. <a href="javascript:void(0)" class="btn exit">Close all pages.</a>
  7. <script>
  8. var query = getQuery();
  9. var depth = (+query.depth) || 0;
  10. document.querySelector('h3').innerHTML = 'Current page depth: ' + depth;
  11. function ready(callback) {
  12. // Call JS Bridge if it has been injected.
  13. if (window.AlipayJSBridge) {
  14. callback && callback();
  15. } else {
  16. // Listen to the injection event if it has not been injected.
  17. document.addEventListener('AlipayJSBridgeReady', callback, false);
  18. }
  19. }
  20. ready(function() {
  21. document.querySelector('.new').addEventListener('click', function() {
  22. AlipayJSBridge.call('pushWindow', {
  23. url: location.pathname + '?depth=' + (1+depth),
  24. });
  25. });
  26. document.querySelector('.back').addEventListener('click', function() {
  27. AlipayJSBridge.call('popWindow', {
  28. data: {
  29. method: 'popWindow',
  30. depth: depth,
  31. }
  32. });
  33. });
  34. document.querySelector('.popTo').addEventListener('click', function() {
  35. AlipayJSBridge.call('popTo', {
  36. index: -2,
  37. data: {
  38. method: 'popTo',
  39. depth: depth,
  40. }
  41. }, function(e) {
  42. if (e.error) {
  43. alert('Error: ' + JSON.stringify(e));
  44. }
  45. });
  46. });
  47. document.querySelector('.exit').addEventListener('click', function() {
  48. AlipayJSBridge.call('exitApp');
  49. });
  50. });
  51. document.addEventListener('resume', function(event) {
  52. alert('content carried when the system returns to the previous page:' + JSON.stringify(event.data));
  53. });
  54. </script>

API

  1. AlipayJSBridge.call('exitApp', {
  2. closeActionType, animated
  3. }, fn);

Input parameters

Name Type Description Required Default value
closeActionType string exitSelf: Exit the local app.
exitTop : Exit the stack-top app.
N -
animated bool Indicates whether to enable the animation N true

Precautions

Pages without an app ID are run with the app ID 20000067. Therefore, calling exitApp on any page will close all pages.