JSAPI

Since 8.1

confirm

Prompts native confirmation dialog.

Usage

AlipayJSBridge.call('confirm', {
  title: 'Hello',
  message: 'Are you sure that you want to close this dialog?',
  okButton: 'Yes',
  cancelButton: 'No'
}, function(e) {
  alert(JSON.stringify(e));
});

Example

alert and confirm dialogs

<h1>Press the following buttons for alert and confirm</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) {
  // Invoke directly if JSBridge is already injected
  if (window.AlipayJSBridge) {
    callback && callback();
  } else {
    // Otherwise listen to `AlipayJSBridgeReady` event
    document.addEventListener('AlipayJSBridgeReady', callback, false);
  }
}
ready(function(){
  document.querySelector('.alert').addEventListener('click', function(){
    AlipayJSBridge.call('alert', {
      title: 'Hello',
      message: 'How are you',
      button: 'OK'
    }, function(e) {
      e && alert(JSON.stringify(e));
    });
  });

  document.querySelector('.confirm').addEventListener('click', function(){
    AlipayJSBridge.call('confirm', {
      title: 'Hello',
      message: 'Are you sure that you want to close this dialog?',
      okButton: 'Yes',
      cancelButton: 'No'
    }, function(e) {
      alert(JSON.stringify(e))
    });
  });
});
</script>

API

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

Input Parameters

NameTypeDescriptionMandatoryDefault
titlestringTitle of the dialogN‘’
messagestringMessage of the dialogN
alignstringMessage alignment, available options: left/center/rightNiOS ‘center’, android ‘left’
okButtonstringText for OK buttonN‘OK’
cancelButtonstringText for cancel buttonN‘Cancel’
fnfunctionCallback function, invoked when button is clickedN

Remarks

  • confirm is a non-blocking API, so if you execute it consecutively twice, i.e., prompts confirm A then confirm B, the eventually prompted dialog is confirm B instead of A.