Ryan Ryan - 10 months ago 55
Javascript Question

How to check if the user can go back in browser history or not

I want using JavaScript to see if there is history or not, I mean if the back button is available on the browser or not.


The only accurate way would be checking the property:


However, the problem with this is that in most browsers this is considered a security violation and usually just returns undefined.


Is a property that others have suggested...
However, the length doesn't work completely because it doesn't indicate where in the history you are. Additionally, it doesn't always start at the same number. IE, for example, starts at 0 while Google Chrome starts at 1 (because of the landing page).

alt text

Most of the time a link is added that calls:




and it's just expected that if you can't go back then clicking the link does nothing.