//返回上個頁面
function back() {
console.log("點擊了後退");
//window.history.back();
//plus.webview.currentWebview().close();
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) { // IE
if (history.length > 0) {
window.history.go(-1);
console.log("IE瀏覽器 點擊了後退");
} else {
console.log("IE瀏覽器 返回到源生");
window.open('baidu://backWebView');
}
} else { //非IE瀏覽器
if (navigator.userAgent.indexOf('Firefox') >= 0 ||
navigator.userAgent.indexOf('Opera') >= 0 ||
navigator.userAgent.indexOf('Safari') >= 0 ||
navigator.userAgent.indexOf('Chrome') >= 0 ||
navigator.userAgent.indexOf('WebKit') >= 0) {
if (window.history.length > 1) {
window.history.go(-1);
console.log("非IE瀏覽器 點擊了後退");
} else {
window.open('baidu://backWebView');
console.log("非IE瀏覽器 返回到源生");
}
} else { //未知的瀏覽器
window.history.go(-1);
console.log("未知的瀏覽器 點擊了後退");
}
}
}
其中window.open('baidu://backWebView');方法是和前端約定的標識,當前端webview攔截到baidu://backWebView時,關閉webview即可。