lyg
lyg
  • 发布:2018-09-15 16:48
  • 更新:2018-10-25 21:15
  • 阅读:19154

uniapp中,如何唤醒第三方app并打开指定的页面

分类:uni-app

比如,在原生的js中,可以使用如下代码实现:

function openApp(url) {  
    var ua = navigator.userAgent.toLowerCase();  
    var tb = url.replace("http://", "").replace("https://", "");  
    if( ua.match(/iphone os 9/i) == "iphone os 9" ) {  
        window.location = "taobao://" + tb;  
        window.setTimeout(function() {window.location = url;},4000);  
    }else{  
        var ifr = document.createElement('iframe');  
        ifr.src = 'taobao://' + tb;  
        ifr.style.display = 'none';  
        document.body.appendChild(ifr);  
        window.location = url;}}  

//只在有优惠券的时候执行  
openApp('https://item.taobao.com/item.htm?id=539608081526');

那么,在uniapp中,该如何实现?

2018-09-15 16:48 负责人:无 分享
已邀请:
DCloud_heavensoft

DCloud_heavensoft

写plus代码到条件编译里,
http://www.html5plus.org/doc/zh_cn/runtime.html#plus.runtime.openURL
Hello H5+的runtime里也有示例

  • 2***@qq.com

    // #ifdef APP-PLUS

    var url = "market://details?id=io.dcloud.HelloH5";

    plus.runtime.openURL( url );

    // #endif

    <navigator/> should have url attribute when using navigateTo, redirectTo or switchTab at uniapp://ready:191

    一直报错

    2018-10-25 20:51

2***@qq.com

2***@qq.com

// #ifdef APP-PLUS
var url = "market://details?id=io.dcloud.HelloH5";
plus.runtime.openURL( url );
// #endif

<navigator/> should have url attribute when using navigateTo, redirectTo or switchTab at uniapp://ready:191

一直报错

  • DCloud_heavensoft

    这是js代码,不是写在标签里的,你点某个按钮时,要在按钮的点击事件上执行这段js,不是用navigator标签

    2018-10-26 00:57

  • 2***@qq.com

    哦哦,非常

    2018-10-26 11:12

  • 2***@qq.com

    感谢

    2018-10-26 11:13

  • 2***@qq.com

    回复 DCloud_heavensoft: 我启动页index.vue 是直接跳转tabBar首页的,如果想通过外部直接唤醒app,我想先打开tabBar首页再跳转相对应的界面,如果唤醒的逻辑写在tabBar首页我觉得应该是没问题的,但是如果我当前的app已经打开了并且停留再其它页面上(非TabBar页面),也能从tabBar唤醒的逻辑不知道能不能执行???

    2019-12-03 15:54

该问题目前已经被锁定, 无法添加新回复