title: How does Browser back button handle Automatic URL redirection?
body: <p>I am trying to create a browser to get the hands on practice on JavaFX. I implemented the Back button with Stack. </p>
  
  <ol>
  <li>When the URL of the page change, add url to Stack(java.util.Stack)</li>
  <li>When back button is pressed, pop 1 item from Stack and show the page</li>
  </ol>
  
  <p>But this does not work in case of URL redirection. Eg. I entered <a href="http://www.google.com" rel="nofollow">http://www.google.com</a> , It automatically redirects to <a href="http://www.google.co.in" rel="nofollow">http://www.google.co.in</a> (India). This makes 2 entries in Stack which corrupts the Back button logic since the page is the same but taken from different locations.</p>
  
  <p>Please assist me in fixing this problem.</p>
  
  <p>Thanks for your help</p>
  
  <pre><code>webEngine.locationProperty().addListener(new ChangeListener&lt;String&gt;(){
  
          @Override
          public void changed(ObservableValue&lt;? extends String&gt; observable, String oldValue, String newValue) {
              //urlField is a text Field
              urlField.setText(newValue);
              addURLToStack(oldValue);
              if(backButtonStack.size() ==1){ //means on last url of Stack
                  backButton.setDisable(true);
              }
              else{
                  backButton.setDisable(false); 
              }}      
      });
   backButton.setOnMouseClicked(new EventHandler&lt;MouseEvent&gt;(){
  
          @Override
          public void handle(MouseEvent event) {
              if(backButtonStack != null &amp;&amp; !backButtonStack.isEmpty()){
                  String poppedURL = backButtonStack.pop();
                  webEngine.load(poppedURL);
  
              }
          }
  
      });
  private void addURLToStack(String url) {
      if(backButtonStack == null){
          backButtonStack = new Stack&lt;String&gt;();
      }
  
      backButtonStack.push(url);
  }
  </code></pre>