h5页面唤醒app的方法-iframe

Posted 晚星@

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了h5页面唤醒app的方法-iframe相关的知识,希望对你有一定的参考价值。

       function a() 
      var iFrame;
      var urlData = 'ownapp://com.pcitc.selfservice?signature=fbfYjkZyAwtGgk9f9RJ4ndWUW2%2B6ddIjVhzhm11JFY71%2BPM0x5lvvY3KYZveVsndwgbq1a7qGbu8%2BywuYI%2FUTw9PY%2Bau2IIEsGgM6OFiUHBTUuWj2uoTFvyho9DGXOjmQZXI%2BLN%2FjuKKFYcWBuYRLErLdjWJF%2BBLIwkXEA79PM5LbdEhhfiyP2JZ59m5DDx5qiT5Icv%2BptOc385z24JAzPyDR97MWLRpn0B64lY9OGauEmm%2B4bPu3oxSVm%2Fsw%2Bg%2B1Cl5%2Fb%2F5yPV7n0tfn4dt03eqwQQ4Pvh4Ui1k1FGyH5prygWOknGH3U2cdELhAr7uv9re%2B9V2t3TqkaRgyr8rwA%3D%3D&encryptedKey=ImBJKSqfmDfGRdZiSZOU2diirBm3duRqhWLOHx48QjW5XyoV2DLu%2BDCO1mJ9dOeAcSov86yJ52fqqM0CqxVrCaZNluBIbswkF135eVCUTAyx%2Bu3Gu4joLm%2FFAlYiefd4d7FjpTbF2IhUUuqaGJYV%2FcirDEfW1W36FcDdU7sqpOQ%3D&cipherText=Mw1NJg%2FVEJ7bjVEFkXZ1TuJEiZ9tUty2A7AWnoE51ak1pX5pfdSTMr%2BuzpDVqQL3kUUt8qYEqJn6kPlcGnnFzUxHWYEFmIZeLW4fqaRq1F0MX0vTB5uM%2BUMlkNmiu7Znx%2F9DoOcISyufnQSlAJz4ZZQEzVWllWLf0TTms1eK%2BGo%3D'
      var u = navigator.userAgent;
      var isandroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
      var isios = !!u.match(/\\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      console.log("isAndroid", isAndroid, isiOS);
      if (isAndroid) 
        //安卓终端使用iframe
        iFrame = document.createElement("iframe");
        iFrame.setAttribute("src", "http://www.baidu.com");
        iFrame.setAttribute("height", "500px");
        iFrame.setAttribute("width", "400px");
        document.body.appendChild(iFrame);
        // 发起请求后这个 iFrame 就没用了,所以把它从 dom 上移除掉
        setTimeout(() => 
          iFrame.parentNode.removeChild(iFrame);
          iFrame = null;
        , 2000)
        // 如果用户没有安装APP,则提示用户去安装APP
        setTimeout(() => 
          window.location.href = "http://www.csdn.net"; // 这里可以自行写一个延时关闭的弹窗,也可以跳转至app下载地址
        , 5000);
      
    

以上是关于h5页面唤醒app的方法-iframe的主要内容,如果未能解决你的问题,请参考以下文章

Android外部唤醒APP跳转指定页面

Android外部唤醒APP跳转指定页面

Android外部唤醒APP跳转指定页面

Android外部唤醒APP跳转指定页面

H5自动唤起支付宝添加好友页面方法

关于H5唤醒APP的功能实现