H5 Container is initialised after window.onload
and AlipayJSBridgeReady
event is emitted when the global variable AlipayJSBridge
is created.
AlipayJSBridge
injection is an asynchronous process, please listen to AlipayJSBridgeReady
event before invoking any JSAPI. We strongly recommend to use [alipayjsapi](alipayjsapi/)
to simplify the process of initialising JSAPI.
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);
}
}