Home > Web Front-end > JS Tutorial > Call APP code using JS

Call APP code using JS

高洛峰
Release: 2017-03-19 15:56:49
Original
2571 people have browsed it

This article shares the code for calling APP using JS as follows

/*
        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) {}
    }
}
Copy after login

The above is the detailed content of Call APP code using JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template