title: Dynamically modify the url using javascript
body: <p>I would like to change the url of the page when the user select another page to visit. The url is dynamically replace the original one. </p>
  
  <p>eg. </p>
  
  <p>If user visit page 1 , the url will be <code>book.html?page=1</code> </p>
  
  <p>If page 30 then <code>book.html?page=30</code> and so on. </p>
  
  <p>However, when I change the link using javascript, it falls into a infinite loop. </p>
  
  <p>It seems I keep visit->change link ->visit ->change link->.... How to fix this problem? </p>
  
  <p>eg. When the link change, don't access the page.</p>
  
  <pre><code>var currURL = $(location).attr('href');
  var index = currURL.indexOf('?');
  currURL = currURL.substring(0, index != -1 ? index : currURL.length);
  // fall into loop
  $(location).attr('href', currURL + '?page=' + pageNo); 
  </code></pre>