title: How to "Monitor"the URL base in WebView
body: <p>So i want to be able to monitor the URL my WebView application is loading. The main thing im trying to accomplish is to keep the WebView inside a specific Website or at least by able to detect when the user is leaving the website's URL. </p>
  
  <p>Example. If i have the base URL of www.google.com and when the user clicks Images, he gets "<a href="http://www.google.com/imghp" rel="nofollow">http://www.google.com/imghp</a>" However it still has the base URL of www.google.com, so if there is a way to monitor when the base URL is no longer www.google.com, such as when a user clicks a search result and is then brought to a different website completely. </p>
  
  <p>The purpose of doing this is that i want to display to the user a dialog or Toast to let them know they are leaving the website that this WebView app is created for.</p>
  
  <p>Any Code, Idea's or suggestions would be greatly appreciated.</p>
  
  <p>Example Code</p>
  
  <pre><code> @Override
   public void onLoadResource(WebView view, String url)
      {
          if (url.equals("http://www.google.com"))
          {
              //do your own thing here
              view.loadUrl(url);
          }
          else
          {
              AlertDialog.Builder localBuilder2 = new AlertDialog.Builder(Webview_Main.this);
              localBuilder2.setTitle("Hey Wait!");
              localBuilder2.setMessage("You currently are about to leave the website\n\nIf you want to stay inside this website, Please click the Go Back button below");
              localBuilder2.setIcon(R.drawable.ic_launcher);
              localBuilder2.setPositiveButton("Go Back",
                      new DialogInterface.OnClickListener() {
                  public void onClick(
                          DialogInterface paramDialogInterface,
                          int paramInt) {
                      web.goBack();
                  }
              });
              localBuilder2.setNegativeButton("Continue",
                      new DialogInterface.OnClickListener() {
                  public void onClick(
                          DialogInterface paramDialogInterface,
                          int paramInt) {
  
                  }
              });
  
              localBuilder2.show();
          };
              super.onLoadResource(view, url);
          }    
  </code></pre>
  
  <p>However this above code doesnt work, only keeps poping up the alert dialog since the URL maybe different.        </p>