Warning dialog

更新时间:
复制 MD 格式

You can use this Application Programming Interface (API) to implement a native warning dialog.

Usage

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

Code examples

alert and confirm:

<h1>Click the buttons below to see 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) {
// If jsbridge is already injected, call it directly.
if (window.AlipayJSBridge) {
  callback && callback();
} else {
  // If not, listen for the injection event.
  document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('.alert').addEventListener('click', function() {
  AlipayJSBridge.call('alert', {
    title: 'Dear',
    message: 'Hello',
    button: 'OK'
  }, function(e) {
    alert(JSON.stringify(e));
  });
});
document.querySelector('.confirm').addEventListener('click', function() {
  AlipayJSBridge.call('confirm', {
    title: 'Dear',
    message: 'Are you sure you want to exit?',
    okButton: 'Yes',
    cancelButton: 'No'
  }, function(e) {
    alert(JSON.stringify(e));
  });
});
});
</script>

API description

Important

Unlike window.alert, alert is non-blocking. This means that if you display two warning dialogs in succession, only the second one is visible.

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

Input parameters

Property

Type

Description

Required

Default value

title

string

The title of the alert dialog.

N

""

message

string

The text in the alert dialog.

N

""

align

string

The alignment of the message. Valid values are `left`, `center`, and `right`.

N

iOS: "center"

Android: "left"

button

string

The button text.

N

"OK"

fn

function

A callback function that is invoked after a user clicks the button.

N

-