Heim  >  Artikel  >  Web-Frontend  >  Rufen Sie APP-Code mit JS auf

Rufen Sie APP-Code mit JS auf

高洛峰
高洛峰Original
2017-03-19 15:56:492501Durchsuche

Dieser Artikel teilt den Code zum Aufrufen von APP mit JS wie folgt

/*
        500ms内,本机有应用程序能解析对应的协议并打开程序,调用该应用;
        如果本机没有应用程序能解析该协议或者500ms内没有打开这个程序,
        则执行setTimeout里面的function,跳转到下载页面。

        iosAppId: appId
        iphoneSchema: IOS App 协议
        iosAppDownloadUrl: IOS App 下载地址 https://itunes.apple.com/cn/app/id@appId@
        androidSchema: Androind App 协议
        androidAppDownloadUrl: Androind App 下载地址
 */function opendApp(iosAppId, iphoneSchema, iosAppDownloadUrl, androidSchema, androidAppDownloadUrl){    if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //IPhone        var loadDateTime = new Date();        window.setTimeout(function() {            var timeOutDateTime = new Date();            if (timeOutDateTime - loadDateTime < 5000) {                window.location = iosAppDownloadUrl.replace("@appId@", iosAppId);//IOS App 下载地址
            } else {                window.close();
            }
        },25);        window.location = iphoneSchema; //IOS App 协议
    }else if (navigator.userAgent.match(/android/i)) {//Androind        try {            window.location =  androidSchema; //Androind App 协议
            setTimeout(function(){                window.location = androidAppDownloadUrl;; //Androind App 下载地址
            },500);
        } catch(e) {}
    }
}

Das obige ist der detaillierte Inhalt vonRufen Sie APP-Code mit JS auf. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn