kml_ckr
kml_ckr

Reputation: 2251

The maximum value of 'window.history.length'

The value of window.history.length is very important in our project to detect the back button is clicked in the browser. However, I realized that window.history.length does not pass 50. How can I solve this?

Upvotes: 7

Views: 15478

Answers (2)

Alberto Zaccagni
Alberto Zaccagni

Reputation: 31580

Depending on whether you need it to be persistent across sessions and surviving a clean of the user information (cache, localStorage, etc.), you might want to adopt different solutions.

One of the solutions could be to do something like this:

window.onpopstate = function(event) {
  var count = parseInt(localStorage.getItem('history-changes-count'), 10);
  localStorage.setItem('history-changes-count', ++count);
};

Note that onpopstate gets invoked only after a user action. It doesn't work if you modify the history programmatically.

More on the subject: Window: popstate event

Upvotes: 5

Sedat Polat
Sedat Polat

Reputation: 1721

It is possible to detect "Back Button Clicked" via iFrames. You can find the answer at Browser Back Button Detection.

Upvotes: 1

Related Questions