title: WebView: open in external browser and not in the app
body: <p>I am using javascript to redirect a page to another, in my app, on a webView:</p>
  
  <p>This is the javascript code:</p>
  
  <pre><code>$(document).ready(function () {
  
          setTimeout(function () {
             window.location.replace('.com.my.app.services.MyClass'); 
          }, 3000);
  
  
      });
  </code></pre>
  
  <p>But, If I click on the back button of my device, in example, during the js loading on the submit of the login, cause the opening of the external browser.
  Is an html page, linked with wicket, and I have this problem ONLY with Android.</p>
  
  <p>I'm very new with all of this.</p>
  
  <p>I tried, to avoid the opening of the browser, this:</p>
  
  <pre><code>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"});
  })();
  </code></pre>
  
  <p>//login.java, on wicket:</p>
  
  <pre><code>  [...]
  
      private void signIn(AjaxRequestTarget target, Class&lt;? extends WebPage&gt; 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 */
            }
      [...]
  </code></pre>
  
  <p>If the user, tap on the back button, the page should be "hidden" and do the trick, avoiding Android to open the browser. 
  But is not working...</p>
  
  <p>Where is my mistake?</p>
  
  <p>Thanks.</p>