After window.onload, the container starts initialization to generate the global variable AlipayJSBridge, and then triggers the event of JSBridge initialization complete (AlipayJSBridgeReady).
Notice:
AlipayJSBridgeinjection is an asynchronous process, and it’s necessary to callAlipayJSBridgeReadyafter monitoring the event.- Be sure to use the
readymethod to perform initialization, otherwise the HTML5 container may fail to obtainAlipayJSBridge.
Use AlipayJSBridgeReady interface
function ready(callback) {// Call directly if JSBridge has been injectedif (window.AlipayJSBridge) {callback && callback();} else {// Monitor the injected events if JSBridge hasn't been injecteddocument.addEventListener('AlipayJSBridgeReady', callback, false);}}
Code sample
The following code sample is the standard writing format for bridge entry:
<h1>Method to use the Bridge </h1><script>function ready(callback) {if (window.AlipayJSBridge) {callback && callback();} else {document.addEventListener('AlipayJSBridgeReady', callback, false);}}ready(function() {alert('bridge ready');});</script>