我有一个页面,我希望它在刷新后保持静止,并且不会再次默认返回首页,因为它会破坏我上次查看它的位置。因此,我一直有时间再次向下滚动以找到我上次查看的区域。有没有办法消除再次向下滚动的负担?
David Bonnici
问问题
2676 次
2 回答
2
抱歉 - 我删除了上面引用的博客(在重定向统计中注意到),但该帖子仍可从 archive.org 获得:http: //web.archive.org/web/20050508195342/patrickfoley.com/2005/01/21 /滚动保护程序/
这是该页面中完整的 PHP 示例:
<HTML>
<HEAD>
<TITLE>Test</TITLE>
<script>
function SaveScrollXY() {
document.Form1.ScrollX.value = document.body.scrollLeft;
document.Form1.ScrollY.value = document.body.scrollTop;
}
function ResetScrollPosition() {
var hidx, hidy;
hidx = document.Form1.ScrollX;
hidy = document.Form1.ScrollY;
if (typeof hidx != 'undefined' && typeof hidy != 'undefined') {
window.scrollTo(hidx.value, hidy.value);
}
}
</script>
</HEAD>
<BODY onload="ResetScrollPosition()">
<form name="Form1" id="Form1" method="post"
onsubmit="SaveScrollXY()" action="index.php">
<input name="ScrollX" id="ScrollX" type="hidden"
value="<?php echo $_REQUEST['ScrollX'] ?>" />
<input name="ScrollY" id="ScrollY" type="hidden"
value="<?php echo $_REQUEST['ScrollY'] ?>" />
<p>This is just a paragraph to make a very long page.</p>
…
<P>This is just a paragraph to make a very long page.</P>
<P>
<input name="TextBox1" type="text"
value="<?php $v = $_REQUEST['TextBox1']; echo $v ? $v + 1 : 1 ?>"
readonly="readonly" id="TextBox1" /></P>
<P>
<input type="submit" name="Button1" value="Post Form"
id="Button1" /></P>
</form>
</BODY>
</HTML>
于 2010-03-12T18:21:53.843 回答
1
于 2009-01-03T17:17:55.963 回答