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
-
On Android, the loading indicator covers the entire interface. Use the system back button to close it.
-
On iOS, if
textis 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. -
showLoadingoperates at the WebView level. CallinghideLoadingin a new WebView after apushwindowevent does not close the loading indicator of the previous WebView. Make sureshowLoadingandhideLoadingare 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 |
N |
0 |
|
autoHide |
bool |
Whether the container automatically hides the loading indicator after the |
N |
true |
|
cancelable |
bool |
Whether the back button closes the loading indicator. Android only. |
N |
true |