This function is often seen on the market. Now it should be very common, Taobao H5, Zhihu H5 and so on. Essence Essence
After clicking, you will adjust the app or open the download page or download it directly.
But I found this function here is a bit different
His logic is to first remind me if I turn on the Zhihu app in the phone (the browser's mechanism is asked to ask the user's operating permit), and then the download prompt pops up.
Solution URL SCHEMEThe URL SCHEME method is supported by both iOS and Android, and the compatibility is better.
Priority to use iframeThe pseudo code is as follows:
Const iframe = document.createElement ('iframe'); iframe.src = 'url scheme'; // url scheme, jump iframe.style.display = 'none'; ODY.APPENDCHILD (iframe);At this time, if all environmental support, you will wake up the app.
But this is an ideal circumstances, and it is more to do this fast logic.
Some systems will intercept iframe's src (this is only one reason that causes the awakening APP failure), because this SRC attribute is a hacker outside the French, and many vulnerabilities are caused by him.
Therefore, at this time, it is necessary to judge the failure of the adjustment of the app.
The pseudo code is as follows:
Const Timer = 1000; Settimeout (Function () {// After successful execution, remove the iframe document.body.removechild (iframe); // Settimeout is less than 2000 that it is considered to evoke an app failure if (date.now () - last <2000 ) {// Execute the failure function // You need to consider the problem you met before (the browser asked the time that the time was less than 2s)} else {// execute the successful function}, timer); understand: In the absence of iframe, we can use window.location.href = URL scheme for compatibility.
The above is the HTML5 page introduced by Xiaobian to try to adjust the APP function. I hope it will be helpful to everyone. If you have any questions, please leave me a message. Xiaobian will reply to everyone in time. Thank you very much for your support for the VEVB Wulin website!