You can call this operation to exit the current stack-top app.
exitApp API usage instruction
AlipayJSBridge.call('exitApp');
Code sample
- Exit the current page:
<h1>Click to exit the current page.</h1><a href="#" class="btn J_demo">Execute</a><script>function ready(callback) {// Call JS Bridge if it has been injected.if (window.AlipayJSBridge) {callback && callback();} else {// Listen to the injection event if it has not been injected.document.addEventListener('AlipayJSBridgeReady', callback, false);}}ready(function() {document.querySelector('.J_demo').addEventListener('click', function() {AlipayJSBridge.call('exitApp');});});</script>
- Page jumping instance:
<h1>Click the following button to jump between pages.</h1><h3></h3><a href="javascript:void(0)" class="btn new">New current page</a><a href="javascript:void(0)" class="btn back">Return by 1 level.</a><a href="javascript:void(0)" class="btn popTo">Return by 2 levels using popTo.</a><a href="javascript:void(0)" class="btn exit">Close all pages.</a><script>var query = getQuery();var depth = (+query.depth) || 0;document.querySelector('h3').innerHTML = 'Current page depth: ' + depth;function ready(callback) {// Call JS Bridge if it has been injected.if (window.AlipayJSBridge) {callback && callback();} else {// Listen to the injection event if it has not been injected.document.addEventListener('AlipayJSBridgeReady', callback, false);}}ready(function() {document.querySelector('.new').addEventListener('click', function() {AlipayJSBridge.call('pushWindow', {url: location.pathname + '?depth=' + (1+depth),});});document.querySelector('.back').addEventListener('click', function() {AlipayJSBridge.call('popWindow', {data: {method: 'popWindow',depth: depth,}});});document.querySelector('.popTo').addEventListener('click', function() {AlipayJSBridge.call('popTo', {index: -2,data: {method: 'popTo',depth: depth,}}, function(e) {if (e.error) {alert('Error: ' + JSON.stringify(e));}});});document.querySelector('.exit').addEventListener('click', function() {AlipayJSBridge.call('exitApp');});});document.addEventListener('resume', function(event) {alert('content carried when the system returns to the previous page:' + JSON.stringify(event.data));});</script>
API
AlipayJSBridge.call('exitApp', {closeActionType, animated}, 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.