title: Make browser delete specific history states
body: <p>I have an ajax controlled website, where I have two types of pages, displayed to the user. For the simplicity let's call them <strong>MAINPAGE</strong>s and <strong>SUBPAGE</strong>s. <strong>MAINPAGE</strong>s contain information, and <strong>SUBPAGE</strong>s are all forms, where the user can add or modify existing information of a <strong>MAINPAGE</strong> for example. </p>
  
  <p>If my site is visited by a user with HTML5 compatible browser, I use HistoryJS to update the url when he/she navigates on my website. Let's pressume the following example:</p>
  
  <p>The user entered my website and navigated to the following pages in the following order, and his <em>history</em> looks something like this:</p>
  
  <blockquote>
    <p>MAINPAGE(1) --> MAINPAGE(2) --> SUBPAGE(1) --> SUBPAGE(2)</p>
  </blockquote>
  
  <p>When the user completes the form on <strong>SUBPAGE(2)</strong>, I want to redirect him immediatly to the last <strong>MAINPAGE</strong> he visited. So for example when the user completes the form, I would like that the users <em>history</em> to be this:</p>
  
  <blockquote>
    <p>MAINPAGE(1) --> MAINPAGE(2)</p>
  </blockquote>
  
  <p>Visually, I am able to achieve this, everything works correctly, but afterwards, in a HTML5 browser, if I press the native back key on the browser, the page tries to revert to <strong>SUBPAGE(1)</strong>, the correct back state from the initial <em>history</em>.</p>
  
  <p><strong>Is it achievable, to delete some of the history states, and if yes, how can I do that?</strong></p>
  
  <p>Here's the code I use so far:</p>
  
  <pre><code>ConverserNavigation.prototype.getPreviousMainAction = function() {
   // NOTE: the code that deals with non HTML5 compatible browsers, 
   // was removed because everything works fine there
   var startFrom, found=false;
  
   if (this.HistoryJS.status==true) startFrom=History.getState().data.id;    
   // if browser is HTML5 compatible, get the current state from History object, 
   // which is a HistoryJS object
  
   while ((!found) &amp;&amp; (startFrom&gt;0)) // find the last MAINPAGE visited by user
   {
       startFrom--;
       if (this.historyData[startFrom].pageData.page != 'quickactions') found=true;   
   }
  
  
  
   if (this.HistoryJS.status==true) History.replaceState({id:startFrom}, this.historyData[startFrom].urlData.title, this.historyData[startFrom].urlData.url);
   // replace the current history state, with the one to where we want to revert
  
   this.currentNavigationId=startFrom;
   this.back(); // render the ui to navigate back to the previous page, works as intended
   for (var i=this.currentNavigationId;i&lt;this.historyData.length;i++) delete this.historyData[i]; // delete the unused history data
  
  }
  </code></pre>