All Products
Search
Document Center

Mobile Platform as a Service:Alert

Last Updated:Feb 26, 2025

This interface is used for native implementation of alert box.

Use alert interface

AlipayJSBridge.call('alert', {
  title: 'Dear',
  message: 'Hello',
  button: 'Confirm'
}, function(e) {
  alert(JSON.stringify(e));
});

Code sample

  • alert and confirm:

    <h1>Click the buttons below to see the different effects</h1>
    <a href="javascript:void(0)" class="btn alert">Click Alert</a>
    <a href="javascript:void(0)" class="btn confirm">Click Confirm</a>
    <script>
    function ready(callback) {
    // Call directly if JSBridge has been injected
    if (window.AlipayJSBridge) {
      callback && callback();
    } else {
      // Monitor the injected events if JSBridge hasn't been injected
      document.addEventListener('AlipayJSBridgeReady', callback, false);
    }
    }
    ready(function() {
    document.querySelector('.alert').addEventListener('click', function() {
      AlipayJSBridge.call('alert', {
        title: 'Dear',
        message: 'Hello',
        button: 'Confirm'
      }, function(e) {
        alert(JSON.stringify(e));
      });
    });
    document.querySelector('.confirm').addEventListener('click', function() {
      AlipayJSBridge.call('confirm', {
        title: 'Dear',
        message: 'Are you sure to exit?',
        okButton: 'Yes',
        cancelButton: 'No'
      }, function(e) {
        alert(JSON.stringify(e));
      });
    });
    });
    </script>

API

AlipayJSBridge.call('alert',{
  title, message, button
}, fn)

Input parameters

Name

Type

Description

Required

Default value

title

String

Title of alert box

N

“”

message

String

Text of alert box

N

align

String

Alignment of message with left/center/right enumeration available

N

“center” for iOS, “left” for Android

button

String

Button text

N

“Confirm”

fn

function

Callback function, which will be called after clicking button.

N

Attentions

  • Unlike window.alert, alert is not a blocking interface. It means that if two alert boxes pop up successively, the one you see finally is the latter one.