Since 9.1removeNotifyListener
Remove listener from listening native notification event.
Usage
AlipayJSBridge.call('removeNotifyListener', {
name: 'fortest'
}, function (result) {
console.log(result);
});
Example
Basic Function
<h1>Please click on the buttons below</h1>
<p>Although the following test is conducted in one page, you can use this API to listen to events happens in other pages</p>
<a href="#" class="btn start">Start Listening</a>
<a href="#" class="btn stop">Stop Listening</a>
<a href="#" class="btn send">Notify</a>
<script>
function callback(e){
alert(JSON.stringify(e));
};
function ready(callback) {
if (window.AlipayJSBridge) {
callback && callback();
} else {
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function(){
document.querySelector('.start').addEventListener('click', function() {
AlipayJSBridge.call('addNotifyListener', {
name:'NEBULANOTIFY_TEST_EVENT'
}, callback);
});
document.querySelector('.stop').addEventListener('click', function() {
AlipayJSBridge.call('removeNotifyListener', {
name:'NEBULANOTIFY_TEST_EVENT'
}, function(e) {
alert(JSON.stringify(e));
});
});
document.querySelector('.send').addEventListener('click', function() {
AlipayJSBridge.call('postNotification', {
name:'NEBULANOTIFY_TEST_EVENT',
data: {
hello: 'world'
}
});
});
});
</script>
API
AlipayJSBridge.call('removeNotifyListener', {
name
}, fn)
Input Parameters
Name | Type | Description | Mandatory | Default |
---|
name | string | Name of event | Y | |
fn | function | Callback function | N | |
Output Parameters
Parameter result:{}
that passed to the callback function
Name | Type | Description |
---|
success | bool | True if the removal is successful |
Error
error | Description |
---|
4 | No permission |
- No matter whether the listener is registered or not, the removal call always returns
success:true
.