1

我的代码在具有 iframe 更改的页面中不起作用 (document.cookie)!回发后!代码是:

$(window).scroll(function() {
oldScroll = $(this).scrollTop();
if (oldScroll >15) {
document.cookie = pathname + oldScroll+'@'; }
}); 

$(window).load(function() {
load();
}); 

function load() {
var pathname = window.location.pathname;var newScroll;
var starPos = document.cookie.indexOf('aspx')+4;
var endPos = document.cookie.indexOf('@');
newScroll = document.cookie.search(";");
var oldPage=document.cookie.substring(0,pathname.length);
$(window).scrollTop(document.cookie.substring(starPos, endPos));
} 
4

1 回答 1

0

我找到了答案,我可以在页面回发中返回滚动

$(document).ready(function () {
var pathname = window.location.pathname;
$(window).ready(function () {
    $(this).scroll(function () {
        oldScroll = $(this).scrollTop();
        if (oldScroll > 100) {
            setCookie("scroll", pathname + oldScroll + "@", '2020');
        }
    });
});


$('#tabContainer').load(function () {
    load();
});
});


function load() {
var pathname = window.location.pathname;
var newScroll;
var starPos = document.cookie.indexOf("aspx") + 4;
var endPos = document.cookie.indexOf("@") ;

if (endPos != -1 && starPos != -1) {
    $(window).scrollTop(document.cookie.substring(starPos, endPos));
}
}

function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
于 2012-11-14T14:06:36.313 回答