Android平臺提前注入5+ API,支持在plusready事件前呼叫
在5+ Runtime環境中,通常情況下需要html頁面決議完成后才會注入5+ API,執行的順序為:
1. 加載html頁面
2. 決議html頁面(下載script/link等節點參考的資源,如js/css檔案)
3. 觸發DOMContentLoaded事件
4. 注入5+ API
5. 觸發plusready事件
這樣導致5+ API生效時間比較延后,在html中參考js執行之后才能呼叫5+ API,通常采用以下代碼呼叫5+ API:
document.addEventListener('plusready',function () {
// 在這里呼叫5+ API
// 如獲取設備唯一標識 plus.device.uuid
},false);
但是在新版本中,將支持提前注入5+ API,可以在plusready事件觸發之前呼叫5+ API,提前引入節點:
<script src="html5plus://ready"></script>
兼容寫法:
if(window.plus){ // 在這里呼叫5+ API }else{// 兼容老版本的plusready事件 document.addEventListener('plusready',function () { // 在這里呼叫5+ API },false); }
注意
1. 僅僅是提前注入5+ API,并不會提前觸發plusready事件(僅步驟4提前操作了)
2. Android3.0及以上平臺才支持提前注入,Android2.*版本無法提前注入
3. 在流應用環境中的wap2app會自動提前注入(第一次參考網路js時注入),不需要添加<script src="html5plus://ready"/>節點
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/169299.html
標籤:HTML5
上一篇:OpenCV:讀取與寫入圖片
