美文网首页
在webview中唤醒APP或者引导用户下载

在webview中唤醒APP或者引导用户下载

作者: jiansheng | 来源:发表于2019-07-31 14:56 被阅读0次

在webview中唤醒APP或者引导用户下载

  • 唤醒APP
function awakeApp() {
    const iframe = document.createElement('iframe');
    iframe.style.display = 'none';
    iframe.src = isIOS ? iosSchema : androidSchema; // APP schema
    document.body.appendChild(iframe);
    iframe.remove();
}
  • 下载APP,IOS系统跳App Store,安卓系统可以跳应用宝
function downloadApp() {
    if (isIOS) {
        const iframe = document.createElement('iframe');
        iframe.style.display = 'none';
        iframe.src = iosStoreUrl;
        document.body.appendChild(iframe);
        iframe.remove();
    } else {
        window.open(androidStoreUrl);
    }
}
  • 先尝试唤醒APP,如果没唤醒成功,2秒后引导下载
function awakeOrDownloadApp() {
    awakeApp();
    setTimeout(() => {
        if (!document.hidden) {
            downloadApp();
        }
    }, 2000);
}

相关文章

网友评论

      本文标题:在webview中唤醒APP或者引导用户下载

      本文链接:https://www.haomeiwen.com/subject/sbftdctx.html