title: How to find the current location index in the browser history
body: <p>Browsers provide a list of the pages visited within a client session through the <code>window.history</code> object. With this, client code can navigate forwards and backwards through the list (using <code>history.back()</code>, <code>history.forward()</code>, and <code>history.go()</code>).</p>
  
  <p>But how can the client code determine <em>where</em> in the history the current page is located? For example, if the client visits pages A, B, and C, the history will contain three items, and the current history item (or state) will be for page C. If the user then clicks the 'back' button, the current page is now B. However, the <code>history.length</code> is still 3, reflecting the fact that three pages were visited in total. How do we determine that the client is currently at item 2 in the history?</p>
  
  <p>A more specific problem is that I want to determine if I am positioned at the first item in the history, so that I can display a 'Close' button which will close the page (assuming that <code>window.opener</code> is not null); at any other position in the history, I want to display a 'Back' button instead which will navigate to the previous page.</p>
  
  <p>This seems to be a curious omission that there is no 'current index' into the history object.</p>
  
  <p><em>Note: This is similar to <a href="https://stackoverflow.com/questions/12895940">question #12895940</a>, but differs in that I really only need to know if I am positioned at the first location in the history.</em></p>