2

Is it possible to tell if there is a back state available (i.e. if the back button in the browser is clickable) without navigating?

Id like to be able to do this in HTML4 and HTML5 if possible.

I can see theres window.history.length, but it doesn't seem to have coherent or consistent behaviour.

Is this possible?

I can see there is this thead, but its rather old. Was wondering if there were HTML5 changes since this thread: How to check if the user can go back in browser history or not

Community
  • 1
  • 1
Andrew Bullock
  • 36,616
  • 34
  • 155
  • 231

1 Answers1

1

From MDN, it seems that when window.history.length is 1, the current page is the only page in history. Anything greater than 1 should mean that the user can navigate backwards. However this is only true for Firefox and Chrome. Looking at w3schools it states

Note: Internet Explorer and Opera start at 0, while Firefox, Chrome, and Safari start at 1.

So then anything greater than 0 in IE and Opera means that the user can navigate backwards.

timrs2998
  • 1,612
  • 18
  • 14