1

I have a webpage which is linked to from a number of different webpages, a user clicks a link on one of the parent pages, arrives at the webpage and completes a task. When the task is complete the user needs to be redirected to the previous page.

I'm aware I could use the window.history.back() / window.history.go(-1) functions - however what i'd really like is something which the browser considers a 'forward' action so as not to confuse the users if they click the forward/back button after a redirect.

I've tried using document.referrer but this gets blanked in the event of a page reload on the webpage.

The solution would need to be compatible back to IE8 (unfortunately!). Any suggestions would be much appreciated.

kaspermoerch
  • 16,127
  • 4
  • 44
  • 67
Rob Rob
  • 150
  • 2
  • 13
  • Do you mean to say that the parent page can vary? but the task remains the same? – Wez Feb 21 '14 at 09:36
  • The parent pages are many and varied but essentially just provide a link and a very small amount of data which customises the task. The task itself remains more or less the same (but just loads some different data based on the input from the parent page) – Rob Rob Feb 21 '14 at 09:38
  • If you provide the task with data from the parent page, is there any reason you can't pass the url from the parent page also? - or knowing the data passed from each parent page provide an if statement at the end of the task with a simple redirect `window.location.href = 'http://gosomewhere.com/parentpage';` – Wez Feb 21 '14 at 09:42
  • Only that there's a large number of pages already there, and i'd prefer to only need to change the 'task' page. – Rob Rob Feb 21 '14 at 09:46
  • That said, the 'task' does have a locking function which can only be called once per process (happens in the controller and essentially if the user already has a lock for this task, it reuses their existing lock). This could store the parent Url in session (i'm assuming here its in server vars!) and then could redirect to it at the end of the process... – Rob Rob Feb 21 '14 at 09:48
  • 1
    If thats PHP your talking about? that sounds like a good way to do it.. however it seems that no matter what language you try and fetch the referer from it can be unreliable - [http://stackoverflow.com/determining-referer-in-php](http://stackoverflow.com/questions/165975/determining-referer-in-php) - Try and store the previous url in session before you move to the task? – Wez Feb 21 '14 at 09:51
  • 1
    thats interesting, thanks. think i'm stuck adding in some extra data from the parent pages then - put as an answer and i'll mark it correct, thanks for your help. – Rob Rob Feb 21 '14 at 10:17

2 Answers2

1

Fetching referrer URLs can be unreliable no matter which language you use https://stackoverflow.com/determining-referer-in-php

The best option is to pass the parent url to the task along with the data that you are already sending, despite the initial time outlay (updating the parent pages to do this) it would be the most reliable.

You could try and do a similar thing with a session or cookie to store the url upon starting the task, but it depends on how you have written the current task as to wether you would still need to modify the parent pages.

Community
  • 1
  • 1
Wez
  • 10,555
  • 5
  • 49
  • 63
0

What about providing a parameter (it may be even the whole url to go after the action) that will let the page know where to go? (like login pages usually do).

It will probably imply modifying all your pages, so it may not be a solution in your case.

richardtz
  • 4,993
  • 2
  • 27
  • 38