jQuery Cookie网址

时间:2013-04-09 10:32:10

标签: jquery cookies back-button

我有这个cookie jQuery.cookie("previousUrl", window.location.href, {path:"/"});来存储上一页的网址。如何将此cookie用作window.location,以便当用户单击“后退按钮”时,它会将它们带到cookie中设置的页面URL? 干杯, 麦克

2 个答案:

答案 0 :(得分:0)

首先获取cookie值

var cookieVal = $.cookie('previousUrl');

然后做

 window.location.href = cookieVal;

答案 1 :(得分:0)

jQuery试试这个:

$(window).unload( function () 
{
   // read cookies value and if its set then window.location.href = cookie value
}

javascript

window.onbeforeunload = function () {
   // read cookies value and if its set then window.location.href = cookie value
}