2014-10-27 57 views
0

我使用的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,在檢票口:

[...] 

    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

其中是您的android webview代碼? – 2014-10-27 11:51:02

+0

我編輯了這個問題。 – 2014-10-27 11:57:07

回答

0

添加此行爲您的網絡視圖。

webView.setWebViewClient(new WebViewClient()); 
+0

謝謝你的回答,並對不起,但我不知道我應該如何添加這行代碼。 我在其他回答中發現了這一行,但是他們只是針對誰在編碼時只使用android。 – 2014-10-27 11:58:01

+0

webview在哪裏。正如你所說你正在使用webview。我不會在代碼中看到webview。 – 2014-10-27 12:03:22

相關問題