How to go back to the previous page using Javascript


well, this is how you can go back to the previous page through Javascript.

javascript:history.go(-1);

Advertisements

Author: Imran Akram

A .NET/SharePoint Consultant and a political enthusiast who believes in putting the feet of the elected and/or unelected officials to fire in order to get good governance.

4 thoughts on “How to go back to the previous page using Javascript”

  1. Going back is easy enough, but what if there is nothing to go back to? I would like to be able to detect if history.go(-1) will actually do anything. If not, have a disable back button displayed.

  2. if there’s nothin to go back to it doesnt do anything… as far as disabling the back button displayed it concerned. Try checking the length of the history object.

    if (history.length) …
    check *may* tell you if browser has history.length property and if
    there was *any* navigation during the current session. The latter check
    may also fail easily if the previous page was the first in the session
    and if you came on the current page via replace() method supported by
    some browsers.

    So history.length doesn’t give you any idea where (by the index
    position) are you now and its counter is not accurate in many
    circumstances.

    if (history.length) {history.go(-1);} is just additional check to avoid
    some (but not all at all) situations.

    I’d suggest u use ur own way of navigation for that. Using Sitemap objects in ASP .NET would be mighty helpful I think. Wish u all the best

    1. Thanks for dropping by. I really think WordPress wont allow that anyway bcz if they allow users to put JS on freely they can do lots of things WordPress doesnt want them to be doing like adding ads etc.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s