Can you detect / redirect the back button by clicking on javascript?

I am trying to detect and change the behavior of the browser if the user clicks the back button.

Is this even possible through Javascript?

+4
source share
3 answers

Wow, I just learned a lot by reading this javascript tutorial. It says the following things:

Mastering the Back Button with Javascript

  • window.onbeforeunload
  • Are you really sure you want to leave my glorious page?
  • Detection when user clicked Cancel
  • Truly Dynamic Pages
  • Some security considerations.
  • You cannot change the story and finally
  • If you MUST control the story

which tells how the story was made with a lock. You can make limited changes. But you can put a replacement URL so that if a person decides to return, he will redirect it to another page. This will be good for security reasons, if the user logs in and then logs out, and the other person clicks the "Back" button, the page will simply be transferred to the replacement page.

check it out Its really short and accurate, informative article / tutorial and contains many java fragments that will help you in each section.

http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript

Hope this helps.

PC

+4
source

I just asked the same question that closed, as this is your duplicate. Here is the gist of my decision:

Form fields are automatically retrieved from the browser cache, thus preserving historical data. while this is true, javascript code runs independently each time.

So, I created a small hidden field to hold a timestamp and compare it with javascript generation time.

Here is the code, I'm sure it can be implemented much better, although the time is short:

$(document).ready(function () { var date = new Date(); var clientMiliseconds = date.getTime(); clientMiliseconds = roundTime(clientMiliseconds); var serverTimeStamp = $('#' + '<%= hfTimeStamp.ClientID %>').val(); serverTimeStamp = roundTime(serverTimeStamp); alert(serverTimeStamp == clientMiliseconds); }); function roundTime(time) { time = Math.floor(time); //since the server renders the time components a few seconds before the page is downloaded //which also depends on where you assign the date on the serverside //we've got a small inaccuracy of few seconds. we neglect these seconds, assuming that it would take the user //a few seconds to click the back button time = time / 10000; time = Math.floor(time); return time; } 
+1
source

It would be possible to implement a link to the "Back" on your html page, and then add your JS function there. However, it is impossible to determine what the user is doing with the browser (for example, clicking the "Back Browser" button) in JS, because this happens outside the context of the loaded page, and there is no standard specification for submitting a web server with data from the browser graphical interface. You can try to develop a custom plug-in for this, so that it works in the browser and transfers the www server with data on this, but again this is a non-standard solution, and not all users installed the third-party plug-in very easily.

Hope this helps.

0
source

All Articles