8***@qq.com
8***@qq.com
  • 发布:2021-11-05 17:16
  • 更新:2021-11-07 16:16
  • 阅读:1485

webview的overrideUrlLoading可以拦截url,但不触发回调函数

分类:HTML5+

代码如下,先访问dcloud主页,再点击顶部的“文档”或“问答社区”,其url中含ask,因此被拦截,但并没有触发callback。

<!DOCTYPE html>  
<html>  
<head>  
<script type="text/javascript">  
function plusReady() {  
    var wv = plus.webview.currentWebview();  
    wv.overrideUrlLoading({mode: "reject", match: ".*ask.*"}, function(e) {  
        console.log("reject url: " + e.url);  
    });  
    setTimeout(function() {  
        this.location.href = "https://www.dcloud.io/";  
    }, 1000);  

}  

if (window.plus)  
    plusReady();  
else  
    document.addEventListener("plusready", plusReady, false);  
</script>  
</head>  
</html>
2021-11-05 17:16 负责人:无 分享
已邀请:
8***@qq.com

8***@qq.com (作者)

应该这样写:

<!DOCTYPE html>  
<html>  
<head>  
<script type="text/javascript">  
function plusReady() {  
    var wv = plus.webview.currentWebview();  
    var nwv = plus.webview.create("https://www.dcloud.io/");  
    nwv.show();  
    nwv.overrideUrlLoading({mode: "reject", match: ".*ask.*"}, function(e) {  
        console.log("reject url: " + e.url);  
    });  
}  

if (window.plus)  
    plusReady();  
else  
    document.addEventListener("plusready", plusReady, false);  
</script>  
</head>  
</html>
8***@qq.com

8***@qq.com (作者)

<!DOCTYPE html>  
<html>  
<head>  
<script type="text/javascript">  
function plusReady() {  
    var wv = plus.webview.open("https://www.dcloud.io/");  
    wv.overrideUrlLoading({mode: "reject", match: ".*ask.*"}, function(e) {  
        console.log("reject url: " + e.url);  
    });  
}  

if (window.plus)  
    plusReady();  
else  
    document.addEventListener("plusready", plusReady, false);  
</script>  
</head>  
</html>

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