Show loading indicator

更新时间:
复制 MD 格式

Displays a global loading indicator over the current page.

How to use the showLoading API

AlipayJSBridge.call('showLoading', {
  text: 'Loading',
});

Code examples

Show or hide the global loading indicator:

<h1>Click the buttons to see different effects</h1>
<p>Note: On Android, the loading indicator covers the entire interface. Use the system back button to close it.</p>
<a href="javascript:void(0)" class="btn show">Show loading</a>
<a href="javascript:void(0)" class="btn delay">Show loading after 2s delay</a>
<a href="javascript:void(0)" class="btn notext">Spinner without text</a>

<script>
function ready(callback) {
  // If AlipayJSBridge 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('.show').addEventListener('click', function() {
    AlipayJSBridge.call('showLoading', {
      text: 'Loading',
    });
    setTimeout(function() {
      AlipayJSBridge.call('hideLoading');
    }, 3000);
  });

  document.querySelector('.delay').addEventListener('click', function() {
    AlipayJSBridge.call('showLoading', {
      text: 'Loading',
      delay: 2000,
    });
    setTimeout(function() {
      AlipayJSBridge.call('hideLoading');
    }, 5000);
  });

  document.querySelector('.notext').addEventListener('click', function() {
    AlipayJSBridge.call('showLoading', {
      text: ' ',
    });
    setTimeout(function() {
      AlipayJSBridge.call('hideLoading');
    }, 3000);
  });
});
</script>

API reference

Important
  • On Android, the loading indicator covers the entire interface. Use the system back button to close it.

  • On iOS, if text is not set, only the title bar and toolbar are clickable. If text is provided, the loading indicator does not cover any content. This was fixed in version 9.9.5 and later.

  • showLoading operates at the WebView level. Calling hideLoading in a new WebView after a pushwindow event does not close the loading indicator of the previous WebView. Make sure showLoading and hideLoading are called within the same WebView.

AlipayJSBridge.call('showLoading',{
  text, delay
})

Input parameters

Property

Type

Description

Required

Default

text

string

The text content. To display no text, pass a single space.

N

"Loading"

delay

int

The delay in milliseconds before the indicator appears. If hideLoading is called before this time, the indicator is not displayed.

N

0

autoHide

bool

Whether the container automatically hides the loading indicator after the pageFinish event. Set to false to keep the indicator visible. Android only.

N

true

cancelable

bool

Whether the back button closes the loading indicator. Android only.

N

true