uniapp应用中使web-view页面(webview)返回上一页+注入js操作页面元素
1、具体页面代码
2、代码解析:
var currentWebview = this. s c o p e . scope. scope.getAppWebview().children()[0];
获取页面webview对象。
onReady() {
var currentWebview = this.
s
c
o
p
e
.
scope.
scope.getAppWebview().children()[0];
currentWebview.addEventListener(“loaded”, function() {
currentWebview.evalJS(
“$(“ul.fed-part-rows a[href*=‘resource.i847.cn’]”).parent().hide();”
);
});
},
监听webview页面加载完成事件,每次加载或跳转页面后都会执行,这里监听完成后给页面注入了一段js代码来隐藏元素。
onBackPress(e) {
this.
s
c
o
p
e
.
scope .
scope.getAppWebview()
.children()[0]
.back();
return true;
}
重写app返回事件,让app返回时触发webview页面返回到上一页。
原文地址:https://www.i847.cn/article/4851.html