a***@163.com
a***@163.com
  • 发布:2019-04-10 19:38
  • 更新:2019-09-05 14:20
  • 阅读:5962

uniapp webview中url拦截问题

分类:uni-app

我想监听webview中的url请求再判断是否是apk下载请求,可是用overrideUrlLoading方法没反应啊

onReady() {  
            var pages = getCurrentPages();  
            var page = pages[pages.length - 1];  
            var currentWebview = page.$getAppWebview();  
            currentWebview.overrideUrlLoading({mode:"reject"},function(event){  
                console.log(event.url)  
            })  
        }
2019-04-10 19:38 负责人:无 分享
已邀请:
DCloud_heavensoft

DCloud_heavensoft

q***@126.com

q***@126.com

请问楼主这个问题是怎么解决的呀,能否告诉我下,我现在也遇到这个问题了,跪求

  • a***@163.com (作者)

    var pages = getCurrentPages();

    var page = pages[pages.length - 1];

    var currentWebview = page.$getAppWebview();

    var children = currentWebview.children();

    var webobj = children[0];

    webobj.overrideUrlLoading({

    mode: "reject",

    match: '(..plist.)|(..(apk|APK|Apk|APk|ApK|aPK|apK)).|(^itms-services.*)'

    }, (event) => {

    uni.request({

    url: this.$api + "/log/addProductLog",

    method: "POST",

    header:{

    "uuid":this.$uuid,

    'userToken':uni.getStorageSync("userinfo").userToken

    },

    data: {

    userPhone: this.info.userPhone,

    accessType: 3,

    productName: this.info.productName,

    productId: this.info.productId,

    channelCode: uni.getStorageSync("userinfo").channelCode,

    customerType: this.userinfo.customerType,

    deviceType: this.isIos ? 1 : 0

    },

    success: (res) => {

    if (res.statusCode == 200) {

    plus.runtime.openURL(event.url);

    plus.statistic.eventTrig("app_productdownload");

    console.log("产品下载日志已记录")

    }

    }

    })

    })

    2019-05-17 11:39

  • a***@163.com (作者)

    这是我写的 监听webview页面下载app行为的代码 ,你看下

    2019-05-17 11:40

  • 辛德瑞拉

    回复 a***@163.com: 你这个正则能够完全 毫无差错的按照规则匹配吗?我写的正则,在本地测试没问题,但是传进来发现,匹配的和实际的不对呢?

    2019-05-18 10:02

  • a***@163.com (作者)

    回复 辛德瑞拉: 基本没问题 因为这边主要是跳转 安卓下载或者苹果下载 ,现在项目上线半个月了 数据还可以

    2019-05-18 11:52

  • a***@163.com (作者)

    回复 辛德瑞拉: 有一点比较难受这个正则字符串不知道怎么写匹配大小写和全局匹配

    2019-05-18 11:53

2***@qq.com

2***@qq.com

请问楼主这个监听webview页面下载app行为的代码是放在什么事件里触发的啊?

  • a***@163.com (作者)

    我是直接在loaded事件中开启的监听

    2019-12-24 12:29

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