public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

Handle back button of the browser

Posted by Virendra Dugar on February 11, 2009

The “Back” browser button cannot be actually disabled by a web application as the browser security will not allow this.
If we want user to stay on the same page, even if user presses back button, then we can use javascript to achieve this.

 

This method will always redirect to the user on the current page itself.

For example, user is on page 1 and user goes to Page 2. Now from page 2 if user press back button of the browser then user will be redirect to the page 2 itself.

window.history contains the collection of the page visited by the user for particular browser session. window.history.go(+1) and window.history.forward(); are same.

But if we want to display web page expired warning on the click of back button, then we must allow the browser to cache the page. This can be achieved by ASP.NET

/*To not to store the page in cache.*/

But one problem with this approach is that this will only work when there are some dynamic content in the page. i.e. change any combo or dropdown box value and then try to press back button.

If you can find out better solution then this please let me also know.

Enjoy…

Advertisements

One Response to “Handle back button of the browser”

  1. Mr L. Truong said

    http://www.boutell.com/newfaq/creating/backbutton.html

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

 
%d bloggers like this: