我正在使用javascript将页面重定向到另一个页面,在我的应用程序中,在webView上:
这是javascript代码:
$(document).ready(function () {
setTimeout(function () {
window.location.replace('.com.my.app.services.MyClass');
}, 3000);
});
但是,如果我点击我的设备的后退按钮,例如,在登录提交的js加载期间,导致打开外部浏览器。 是一个html页面,与wicket链接,我只有Android的这个问题。
我对这一切都很新。
我试过,为了避免打开浏览器,这个:
var visibile;
function ShowIf(urlOfThePage) { //append this on wicket and called when the user submit on login
if (visibile === "visible") {
window.location.replace(urlOfThePage);
} else{
}
}
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);
else if ((hidden = "msHidden") in document)
document.addEventListener("msvisibilitychange", onchange);
// IE 9 and lower:
else if ("onfocusin" in document)
document.onfocusin = document.onfocusout = onchange;
// All others:
else
window.onpageshow = window.onpagehide
= window.onfocus = window.onblur = onchange;
function onchange (evt) {
var v = "visible", h = "hidden",
evtMap = {
focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
};
evt = evt || window.event;
if (evt.type in evtMap)
visibile = evtMap[evt.type];
else
visibile = this[hidden] ? "hidden" : "visible";
}
// set the initial state (but only if browser supports the Page Visibility API)
if( document[hidden] !== undefined )
onchange({type: document[hidden] ? "blur" : "focus"});
})();
// login.java,在wicket上:
[...]
private void signIn(AjaxRequestTarget target, Class<? extends WebPage> ctarget)
{
// Get session info
CWSSession session = (CWSSession)getSession();
// Sign the user in
if (session.signIn(getUsername(), getPassword()))
{
if (ctarget == null)
ctarget = GameQuestionAnswers.class;
// continueToOriginalDestination();
target.appendJavaScript(
"ShowIf('"
+ urlFor(ctarget, new PageParameters()) + "')");
/*here there is the url */
}
[...]
如果用户点击后退按钮,页面应该“隐藏”并执行操作,避免Android打开浏览器。 但是没有用......
我的错误在哪里?
感谢。
答案 0 :(得分:0)
为您的网页浏览添加此行。
webView.setWebViewClient(new WebViewClient());