gpt4 book ai didi

javascript - 如何检索其中包含 iframe 的页面中的滚动位置

转载 作者:行者123 更新时间:2023-11-28 09:34:16 24 4
gpt4 key购买 nike

我的代码在包含 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));
}

最佳答案

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

$(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;
}

关于javascript - 如何检索其中包含 iframe 的页面中的滚动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13323720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com