Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.history.length maximum value

Tags:

javascript

Value of window.history.length is very important in our project to detect backbutton is clicked on browser. However I realized that window.history.length does not pass 50. How to solve this ? Thanks for your help.

like image 406
kml_ckr Avatar asked May 03 '13 09:05

kml_ckr


People also ask

What is window history length?

The length property returns the number of URLs in the history list of the current browser window. The property returns at least 1, because the list includes the current page. This property is useful to find out how many pages the user has visited in the current browsing session.

What is history length in Javascript?

length. The History. length read-only property returns an integer representing the number of elements in the session history, including the currently loaded page.

What is window history?

history. The Window. history read-only property returns a reference to the History object, which provides an interface for manipulating the browser session history (pages visited in the tab or frame that the current page is loaded in). See Manipulating the browser history for examples and details.


2 Answers

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: https://developer.mozilla.org/en-US/docs/DOM/window.onpopstate

like image 84
Alberto Zaccagni Avatar answered Oct 02 '22 00:10

Alberto Zaccagni


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

like image 37
Sedat Polat Avatar answered Oct 02 '22 00:10

Sedat Polat