I have this cookie jQuery.cookie("previousUrl", window.location.href, {path:"/"});
to store the previous page url. How can I use this cookie as a window.location so that when a user clicks a "back button" it will take them to the page url set in the cookie?
Cheers,
Mike
Asked
Active
Viewed 1,886 times
0

user1813098
- 25
- 1
- 7
-
just read cookies value and on window.back call window.location.href – Dipesh Parmar Apr 09 '13 at 10:34
2 Answers
0
First get cookie value
var cookieVal = $.cookie('previousUrl');
then do
window.location.href = cookieVal;

chandresh_cool
- 11,753
- 3
- 30
- 45
-
Thanks @chandresh_cool. This works pertaining to my question. For some reason though when the user clicks on a link the previousURL cookie stores the active link url and not the current page url. Any ideas on that one? – user1813098 Apr 09 '13 at 11:07
-
That is because your this function jQuery.cookie("previousUrl", window.location.href, {path:"/"}); stores the redirected url or the clicked url. – chandresh_cool Apr 09 '13 at 11:13
0
In a jQuery
try this :
$(window).unload( function ()
{
// read cookies value and if its set then window.location.href = cookie value
}
In javascript
:
window.onbeforeunload = function () {
// read cookies value and if its set then window.location.href = cookie value
}

Dipesh Parmar
- 27,090
- 8
- 61
- 90