javascriptjqueryhistory.js

use javascript history to discard consecutive clicks on the same page


So, I'n NOT a frontend guy, please bear with me..

I have pages, where you submit forms (target and current urls are identical) a number of times, before you wan't to go back to the previous page. The way the submits are processed, is that the form is posted, and then the user is redirected, so that a reload doesn't re-submit(POST) the form - I'm not sure if this is the optimal approach to achieve this..

The issue is that this will only take the user back to the same page, since if eg. a form on page A was submitted twice, the history will have:

  1. page A (current)
  2. page A (submit, yielding a redirect)
  3. page A (previous load)
  4. page A (submit, yielding a redirect)
  5. page A (original load)
  6. previous page

Now I'd like the back button to take the user back to the previous page (#6), and in order to do that I'm guessing I'd need to introduce code on each page (with forms at least) which:

  1. checks if the referrer has identical url as the current one, and if so, does history.popState
  2. on submitting any form, check if the target and current urls are identical does history.popState

Is this a sound strategy, or is there are better way to achieve this?


Solution

  • This doesn't seem possible, so I took another route, where I'd avoid using the back button, but rather offer links to the previous page, based on the context.