You cannot check window.history.length as it contains the amount of pages in you visited in total in a given session: window.history.length (Integer) Read-only. Returns the number of elements in the session history, including the currently loaded page. For example, for a page loaded in a new tab this property returns 1. Cite 1 Lets say a user visits your page, clicks on some links and goes back: www.mysite.com/index.html <-- first page and now current page <----+ www.mysite.com/about.html | www.mysite.com/about.html#privacy | www.mysite.com/terms.html <-- user uses backbutton or your provided solution to go back Now window.history.length is 4. You cannot traverse through the history items due to security reasons. Otherwise on could could read the user's history and get his online banking session id or other sensitive information. You can set a timeout, that will enable you to act if the previous page isn't loaded in a given time. However, if the user has a slow Internet connection and the timeout is to short, this method will redirect him to your default location all the time: