Exits the application at the top of the current stack.
Usage
AlipayJSBridge.call('exitApp');
Code examples
-
Exit the current page:
<h1>Click to exit the current page</h1> <a href="#" class="btn J_demo">Run</a> <script> function ready(callback) { // If the JSBridge is already injected, call the callback directly. if (window.AlipayJSBridge) { callback && callback(); } else { // If not, listen for the injection event. document.addEventListener('AlipayJSBridgeReady', callback, false); } } ready(function() { document.querySelector('.J_demo').addEventListener('click', function() { AlipayJSBridge.call('exitApp'); }); }); </script> -
Page navigation example:
<h1>Click the buttons below to navigate between pages</h1> <h3></h3> <a href="javascript:void(0)" class="btn new">Open a new page</a> <a href="javascript:void(0)" class="btn back">Go back one level</a> <a href="javascript:void(0)" class="btn popTo">Go back 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) { // If the JSBridge is already injected, call the callback directly. if (window.AlipayJSBridge) { callback && callback(); } else { // If not, listen for the injection event. 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('An error occurred: ' + JSON.stringify(e)); } }); }); document.querySelector('.exit').addEventListener('click', function() { AlipayJSBridge.call('exitApp'); }); }); document.addEventListener('resume', function(event) { alert('Content passed from the previous page: ' + JSON.stringify(event.data)); }); </script>
API reference
Important
Pages without a specified AppId use the default AppId 20000067. Calling exitApp from such a page closes all pages.
AlipayJSBridge.call('exitApp', {
closeActionType, animated
}, fn);
Input parameters
|
Name |
Type |
Description |
Required |
Default |
|
closeActionType |
string |
|
N |
- |
|
animated |
bool |
Specifies whether to animate the exit. |
N |
true |
该文章对您有帮助吗?