代码之家  ›  专栏  ›  技术社区  ›  user1813098

jQuery Cookie URL

  •  0
  • user1813098  · 技术社区  · 11 年前

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

    2 回复  |  直到 11 年前
        1
  •  0
  •   chandresh_cool    11 年前

    首先获取cookie值

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

    那就去吧

     window.location.href = cookieVal;
    
        2
  •  0
  •   Dipesh Parmar    11 年前

    在一个 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
    }