All Products
Search
Document Center

Remove notification listener

Last Updated: Feb 24, 2021

You can call this interface to remove native notification listening.

removeNotifyListener API usage instruction

 
  1. AlipayJSBridge.call('removeNotifyListener', {
  2. name: 'fortest'
  3. }, function (result) {
  4. console.log(result);
  5. });

Code sample

The following example shows the basic functions.

 
  1. <h1>Click the following button to perform a test.</h1>
  2. <p>In this example, multiple operations are called on the same page. This API supports communication among different apps.</p>
  3. <a href="#" class="btn start">Start listening.</a>
  4. <a href="#" class="btn stop">Stop listening.</a>
  5. <a href="#" class="btn send">Send a notification.</a>
  6. <script>
  7. function callback(e){
  8. alert(JSON.stringify(e));
  9. };
  10. function ready(callback) {
  11. // Call JS Bridge if it has been injected.
  12. if (window.AlipayJSBridge) {
  13. callback && callback();
  14. } else {
  15. // Listen to the injection event if it has not been injected.
  16. document.addEventListener('AlipayJSBridgeReady', callback, false);
  17. }
  18. }
  19. ready(function(){
  20. document.querySelector('.start').addEventListener('click', function() {
  21. AlipayJSBridge.call('addNotifyListener', {
  22. name:'NEBULANOTIFY_TEST_EVENT' // Events sent by the HTML5 must be listened to by adding the prefix NEBULANOTIFY_.
  23. }, callback);
  24. });
  25. document.querySelector('.stop').addEventListener('click', function() {
  26. AlipayJSBridge.call('removeNotifyListener', {
  27. name:'NEBULANOTIFY_TEST_EVENT' // Events sent by the HTML5 must be listened to by adding the prefix NEBULANOTIFY_.
  28. }, function(e) {
  29. alert(JSON.stringify(e));
  30. });
  31. });
  32. document.querySelector('.send').addEventListener('click', function() {
  33. AlipayJSBridge.call('postNotification', {
  34. name:'TEST_EVENT' // Events sent by the HTML5 must be listened to by adding the prefix NEBULANOTIFY_.
  35. data: {
  36. hello: 'world'
  37. }
  38. });
  39. });
  40. });
  41. </script>

API

 
  1. AlipayJSBridge.call('removeNotifyListener', {
  2. name
  3. }, fn)

Input parameters

Name Type Description Required Default value
name String Notification name Y “”
fn function Callback function N -

Output parameters

result: {success}: the parameter transferred in the callback function.

Name Type Description
success bool Whether notification listening is removed successfully

Error code

Error code Description
4 Unauthorized call

Precautions

  • success: true is returned regardless of whether the remove operation is registered.