Use this API to close the current page.
Using the popWindow API
// Closes the current page.
AlipayJSBridge.call('popWindow');Code examples
Close the current page:
<h1>Close the current page</h1> <a href="#" class="btn J_demo">Run</a> <script> function ready(callback) { // If JSBridge is injected, call the function directly. if (window.AlipayJSBridge) { callback && callback(); } else { // If JSBridge is not injected, listen for the injection event. document.addEventListener('AlipayJSBridgeReady', callback, false); } } ready(function(){ document.querySelector('a').addEventListener('click', function() { AlipayJSBridge.call('popWindow'); }); }); </script>Close the current page and pass data:
<h1>Click "New Window" and then "Go Back" to see the result.</h1> <a href="#" class="btn pop">Go Back</a> <a href="#" class="btn new">New Window</a> <script> function ready(callback) { // If JSBridge is injected, call the function directly. if (window.AlipayJSBridge) { callback && callback(); } else { // If JSBridge is not injected, listen for the injection event. document.addEventListener('AlipayJSBridgeReady', callback, false); } } ready(function() { document.querySelector('.new').addEventListener('click', function() { AlipayJSBridge.call('pushWindow', { url: location.pathname }); }); document.querySelector('.pop').addEventListener('click', function() { AlipayJSBridge.call('popWindow', { data: { from: location.href, info: Date.now() } }); }); document.addEventListener('resume', function(event) { alert('Content passed on page resume: ' + JSON.stringify(event.data)); }); }); </script>
API reference
Important
To learn how to receive data passed with popWindow, see Resume page (resume event).
AlipayJSBridge.call('popWindow', {
data
})Input parameters
Name | Type | Description | Required |
data | object | The content to pass to the page that is revealed in the current app. Data cannot be passed across app IDs. | N |