0

每次页面刷新时它都会转到页面顶部,我希望它保持原样,我很确定它与函数 move() {window.location = window.location.href} 有关。这是代码。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
 <meta http-equiv="refresh" content="83">
 <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
 <META HTTP-EQUIV="Expires" CONTENT="-1">
 <title>[DashboardDescrip]</title>

 <style type="text/css">
body
{ 
    background-image: 
    url('../Images/Black-BackGround.gif');
    background-repeat: repeat
}
 </style>
 </head>

 <script type="text/javascript">
var time = null
function move() { window.location = window.location.href }
4

4 回答 4

2

好吧,您实际上并没有刷新页面..您将其重定向到同一页面..要刷新使用:

location.reload(); 

http://www.w3schools.com/jsref/met_loc_reload.asp

这可能仍然无法解决您的问题..您将不得不寻找一些脚本..您使用的是 asp.net 吗?

于 2013-07-14T15:11:26.203 回答
1

也许以下代码对您有用?来源

<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>
于 2013-07-14T15:16:18.473 回答
1

Shawn313131 为我想出了这个答案,所以归功于他而不是我!!!

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        body { 
            background-image: url('../Images/Black-BackGround.gif');
            background-repeat: repeat;
        }
        body td {
           font-Family: Arial; 
           font-size: 12px; 
        }
        #Nav a { 
            position:relative; 
            display:block; 
            text-decoration: none; 
            color:black; 
        }
    </style>
    <script type="text/javascript">
        function refreshPage () {
            var page_y = document.getElementsByTagName("body")[0].scrollTop; 
        window.location.href = window.location.href.split('?')[0] + '?page_y=' + page_y;

        }
        window.onload = function () {
            setTimeout(refreshPage, 35000);
            if (window.location.href.indexOf('page_y') != -1 ) {
                var match = window.location.href.split('?')[1].split("&")[0].split("=");
                document.getElementsByTagName("body")[0].scrollTop = match[1];

            }
        }
    </script>
</head>
<body>
于 2013-07-15T22:45:26.187 回答
0

我相信你正在寻找这样的东西:

var pos = $(window).scrollTop();

..// Some Code Later, or after page refresh & retrieving the value from a cookie

$(window).scrollTop(pos);
于 2013-07-14T15:15:38.300 回答