sudip
sudip

Reputation:

How to control over browser back button

I want a confirmation window on click of a browser back button. If I press yes then the previous page will get load ortherwise I will remain in the same page?

Any suggestion is highly appreciated.. But please be on track.. my question is straight forward

thx in advance..

Upvotes: 0

Views: 5117

Answers (3)

jimbo
jimbo

Reputation: 1

I use noscript for this very reason. I insist on having control of my browser not the site that I am visiting. I only allow scripts for certain sites. For any site that disables my back button,I don't allow it to run scripts.

Upvotes: 0

LapTop006
LapTop006

Reputation: 512

Generally if using the back button can cause issues you already have bigger problems.

What you probably want to do is check that you do things like this:

  • Use POST for all requests that alter data
  • Use nonce's (unique ID's) to enure forms don't get submitted twice

Upvotes: 1

Jimmy Stenke
Jimmy Stenke

Reputation: 11220

Why do you want to do that?

You can prevent them from leaving the page by using Javascript, but if you can't use that, it's not possible to do anything about it.

Generally you should use the unload event in the body (in jQuery for instance, just add

jQuery(window).unload(function(evt){
   if(!confirm('Do you really want to leave')){
      evt.preventDefault();
   }});

Prototype have something similar, and for pure Javascript, I guess that it still depends on the browser you're using, but window.unload = function(evt){return false;} might work.

Don't remember the correct syntax for it though.

but I do not know if you can limit that for only the back or if it will trigger for all the unloads (like clicking on a link, closing the browser etc.)

If you want to stop them because they might have unsaved data in a form, then that is ok. If you want to stop them from going back for another reason than that, I think you should rethink why.

Upvotes: 4

Related Questions