Rob Rob
Rob Rob

Reputation: 160

Forward redirect to previous page

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.

Upvotes: 1

Views: 90

Answers (2)

Wez
Wez

Reputation: 10712

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.

Upvotes: 1

richardtz
richardtz

Reputation: 4993

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.

Upvotes: 0

Related Questions