HTML5 write links to open iOS and Android native apps

Source: Internet
Author: User

1. Set the link in HTML

<a id="open-app" href="[scheme]://[host]/[path]?[query]">打开应用</a>

Href= "[Scheme]://[host]/[path]? [Query] "
Scheme can be set up in the app itself as arbitrary, the Android and iOS are set to the same
2, if the local application exists, directly open the app; if it doesn't exist, time to jump to AppStore
You need to determine whether the browser is in iOS or Android

varOpenapp = function () {    varBtnopenapp = document.getElementById ("Open-app"); Btnopenapp.onclick = function () {        //Open local application function        varopen= function(URL){            varTimeout function try_to_open_app() {Timeout = SetTimeout ( function(){window.location.href="url"; Console.log ("a")                       },Ten);        } Try_to_open_app (); }if(/android/i. Test (Navigator.useragent)) {//alert ("This is Android ' browser."); /This is the Android platform under the browser            if(/micromessenger/i. Test (Navigator.useragent)) {alert ("This is Micromessenger browser, please open it using your local browser");//This is the platform under the browser}Else{Open (Andorid app market URL); }        }if(/(Iphone|ipad|ipod|ios)/ I. Test (Navigator.useragent)) {//alert ("This is IOS ' browser."); /This is the iOS platform under the browser            if(/micromessenger/i. Test (Navigator.useragent)) {alert ("The built-in browser does not support opening the local app, please click on the upper right corner to open with local browser");//This is the platform under the browser}Else{Open (iOS app market URL); }        }    };}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HTML5 write links to open iOS and Android native apps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.