You can use popWindow to close the current page.
// Close the current page
AlipayJSBridge.call('popWindow');
<h1>Close current page</h1>
<a href="#" class="btn J_demo">Execute</a>
<script>
function ready(callback) {
// Invoke directly if JSBridge is already injected
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Otherwise listen to `AlipayJSBridgeReady` event
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function(){
document.querySelector('a').addEventListener('click', function() {
AlipayJSBridge.call('popWindow');
});
});
</script>
<h1>Click"New window",then click "Pop window" to check this demo</h1>
<a href="#" class="btn pop">Pop window</a>
<a href="#" class="btn new">New window</a>
<script>
function ready(callback) {
// Invoke directly if JSBridge is already injected
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Otherwise listen to `AlipayJSBridgeReady` 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('Data from closed window' + JSON.stringify(event.data));
});
});
</script>
AlipayJSBridge.call('popWindow', {
data
})
Name | Type | Description | Mandatory | Default | Version |
---|---|---|---|---|---|
data | object | The data to be received by the resumed page It is not possible to pass data to page with different appId | N |
closeWebview
is an alias to popWindow
, you can call the API with AlipayJSBridge.call('closeWebview')
popWindow
is received in resumed page