You can call this interface to close the current page.
popWindow API usage instruction
// Close the current page.
AlipayJSBridge.call('popWindow');
Code sample
- Close the current page:
<h1>Close 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('a').addEventListener('click', function() {
AlipayJSBridge.call('popWindow');
});
});
</script>
- Close the current page and transfer data:
<h1>Click "New window" and then "Return" to view the effect.</h1>
<a href="#" class="btn pop">Return</a>
<a href="#" class="btn new">New window</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('.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 carried when the system returns to the previous page:' + JSON.stringify(event.data));
});
});
</script>
API
AlipayJSBridge.call('popWindow', {
data
})
Input parameters
Name | Type | Description | Required | Default value |
---|---|---|---|---|
data | object | Content transferred to the page that is about to pop up within the current app. Data cannot be transferred across apps of different IDs. | N | - |
Precautions
For details about how data carried during popWindow
is received, see Resume a page (resume event).