How to solve the problem of plusready compatibility in HTML5 API
This article mainly introduces the relevant knowledge of "how to solve the plusready compatibility problem in HTML5 API". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to solve the plusready compatibility problem in HTML5 API" can help you solve the problem.
Android platform injects 5 + API in advance, which can be called before the plusready event.
In a 5 + Runtime environment, 5 + API is usually injected after the parsing of the html page is completed, and the order of execution is as follows:
1. Load the html page
two。 Parse html pages (download resources referenced by nodes such as script/link, such as js/css files)
3. Trigger DOMContentLoaded event
4. Inject 5 + API
5. Trigger plusready event
As a result, the effective time of 5 + API is delayed. 5 + API can only be called after referencing js execution in html. Usually, the following code is used to call 5 + API:'.
Document.addEventListener ('plusready',function () {/ / call 5 + API / / for example, get the device unique ID plus.device.uuid}, false)
However, in the new version, the injection of 5 + API in advance will be supported. You can call 5 + API before the plusready event is triggered to introduce nodes ahead of time:
Compatible writing:
If (window.plus) {/ / call 5 + API} else {/ / compatible with the older version of plusready event document.addEventListener ('plusready',function () {/ / call 5 + API}, false) here;}
Be careful
1. Just injecting 5 + API in advance will not trigger the plusready event in advance (only step 4 is done in advance)
2. Advance injection is supported on Android3.0 and above platforms, and cannot be injected in Android2.* version.
3. Wap2app in the streaming application environment is automatically injected in advance (when the network js is referenced for the first time), and there is no need to add nodes
This is the end of the content about "how to solve the problem of plusready compatibility in HTML5 API". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.