Monkey Raptor

Tuesday, November 4, 2014

JavaScript: Browser History Length

We can access the browser session history object length by using:

It will return the number of browsing session history.

In other browsers other than Internet Explorer (less than or equal to 9 version, maybe) genre, the current page is also added as a history object element. Thus, it will return 1 even though we have nowhere to go to.
(Old) Internet Explorer will return 0 if you have no other page to go to (previous/next).

The new Internet Explorer (10 - 11) behaves like the other ones now. More of Chrome-like looks.

If we flush/empty the browsing history, then it will also reset the amount of length of history.


No returned value
For security reason, this object doesn't return any value, except the read-only length.


Methods
The (cross-browser) available methods are:
  • back()
    Action:
    the current window will change state to the previous page if the previous page exists.
    Example:
    history.back()
    This has no returned value.
  • forward()
    Action:
    the current window will change state to the next page if the next one exists in the object.
    Example:
    history.forward()
    This has no returned value.
  • go(integer)
    Action:
    can go back or forward.
    Examples:
    • history.go(-1) is equivalent with history.back()
    • history.go(1) is equivalent with history.forward()
    This also has no returned value.
    If the integer we put is out of bound, the method will return nothing (no error).


Doodle

I made an animation with the JavaScript itself to capture and show your browser history.length below.



Link for further exploration
Updated Nov 17, 2014
JavaScript: Browser History Length
https://monkeyraptor.johanpaul.net/2014/11/doodle-browser-history-length-javascript.html?m=0

No comments

Post a Comment

Tell me what you think...