跳转到表单的页面顶部,提交到新页面


Jump to top of page on form submit to new page

我在PHP页面上有一个表单:

<form name="SendEmail01" method="post">
    form items here...
</form>

然后我这样处理:

if(isset($_POST["Submit"]))
{
All tasks here...
$thanks_redirect = 'http://' . $_SERVER["SERVER_NAME"] . '/thanks.php#top';
header("location: $thanks_redirect");
}

问题是,处理页面上的提交按钮在页面的下方很低,当我按下"提交"时,它会正确处理并正确跳转到thanks.php页面,但页面保持在同一位置,看起来只是一个空白页面(除非用户向上滚动)。

我尝试过Javascript和HTML超链接,比如#top,但它不会跳回页面的顶部,在thanks.php页面上,它说它都被正确处理了。

有人能帮助我在处理完表格后如何将thanks.php页面滚动回页面顶部吗?

编辑:我在thanks.php页面上有这个,用户在提交时会被重定向:

<html>
<head>
<script type="text/javascript">
var lockit=setInterval("window.scrollTo(0,0)",10)
</script>
<style>
form {
    display: inline;
}
input
{
color: #000000;
background: #ffffff;
border: 1px solid #000000;
padding: 4px;
font-size:13px;
font 
}
#submit {
 color: #000000;
 font-size: 13px;
 width: 110px;
 height: 30px;
 border: 1px solid #000000;
 margin: 0;
 padding: 0;
 background: #66ff66 url(image) 0 0 no-repeat; 
}
#buttons {
 color: #000000;
 font-size: 13px;
 width: 80px;
 height: 25px;
 border: 1px solid #000000;
 margin: 0;
 padding: 0;
 background: #66ff66 url(image) 0 0 no-repeat; 
}
</style>
</head>
<body>
<script type="text/javascript">
$('html, body').animate({ scrollTop: 0 }, 'fast');
</script>
<?php
session_start();
$loggedin_user = $_SESSION['serial'];
$local_path = $_SESSION['local_path'];
$full_path = $_SESSION['full_path'];
?>
<font face="Verdana, Arial, Helvetica, sans-serif" color="black">
<form action="http://<?php echo $_SERVER["SERVER_NAME"]; ?>/login.php?log_out">
    <input type="submit" value="Logout" id="buttons">
</form>
<form action="<?php echo $full_path;?>index.php">
    <input type="submit" value="Go Back" id="buttons">
</form>
<p><b>Success!</p></b>
<p>Your changes have been submitted.. 
<p>Please note that not <u>all</u> changes are made in real-time, some changes may only be updated when the server checks for new configuration.</p>
</body>
</html>

谢谢。

我想把它作为注释添加,但它有点太长了。

我制作了这个页面:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <p>Calibri Text</p>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <form>
        <input type="submit" />
    </form>
</body>
</html>

提交时,页面会跳到顶部,并重定向到另一个页面,所以你不应该有这个问题,除非你的jQuery中有一些内容引起了关注。

试试这个。

$('html, body').animate({ scrollTop: 0 }, 'fast');

您不需要任何custom divs。只要有一个简单的页面。

<html>
<head>
<title>Thanks Page</title>
</head>
<body>
Well Thanks bro!
</body>
</html>