The interface is used for the native implementation of the confirmation box.
Use confirm interface
AlipayJSBridge.call('confirm', {
title: 'Dear',
message: 'Are you sure to exit?',
okButton: 'Yes',
cancelButton: 'No'
}, 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) {
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, okButton, cancelButton
}, fn)
Input parameters
Name | Type | Description | Required | Default value | Version |
---|---|---|---|---|---|
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 | 10.0.5 |
okButton | string | Text of confirm button | N | ‘Confirm’ | |
cancelButton | string | Text of cancel button | N | ‘Cancel’ | |
fn | function | Callback function which will be called after clicking button | N |
Attentions
- Similar to
alert
,confirm
is also not a blocking interface. It means that if two alert boxes pop up successively, the one you see finally is the latter one.