redirect to same page to anchor

Need make redirect from http://sitename.com/cat/index.php to http://sitename.com/cat/index.php#anchor

I tried 2 ways: php redirect and meta refresh

PHP redirect

<?php
    $URL = "http://sitename.com/cat/index.php#anchor";
    header("Location: $URL");
?>
<html>
....

meta refresh

<html>
    <head>
    ... 
    <meta http-equiv="refresh" content="0;url=http://sitename.ru/cat/index.php#anchor">
    ...
    </head>
...
</html>

In result to both ways I have cycling page refresh.

How to correctly solve this problem ?


您不需要重定向页面,只需设置window.location.hash

window.location.hash="anchor";
链接地址: http://www.djcxy.com/p/1954.html

上一篇: 将变量传递给window.location href

下一篇: 重定向到相同的页面来锚定