跳轉到新頁面後返回到前一頁瀏覽的歷史位置

/*返回上次瀏覽位置*/
$(function () {
var str = window.location.href;
str = str.substring(str.lastIndexOf("/") + 1);
if ($.cookie(str)) {html

$("html,body").animate({ scrollTop: $.cookie(str) }, 1000);
}
else {
}
})jquery

$(window).scroll(function () {
var str = window.location.href;
str = str.substring(str.lastIndexOf("/") + 1);
var top = $(document).scrollTop();
$.cookie(str, top, { path: '/' });
return $.cookie(str);
})
/*返回上次瀏覽位置*/cookie

這個是用jquery寫的,因此用的時候要引入jquery庫,和jquery.cookie.jsspa

相關文章
相關標籤/搜索