2012-08-31 175 views
14

需要进行从http://sitename.com/cat/index.php重定向到http://sitename.com/cat/index.php#anchor重定向到同一页面锚

我尝试2种方式:PHP重定向和元刷新

PHP重定向

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

元刷新

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

在两种方式中,我都有循环页面刷新的结果。

如何正确解决这个问题?

+2

试试这里的解决方案:http://stackoverflow.com/a/506004/889678 – mgraph

+0

谢谢。它按我的意愿工作。 – v2p

回答

9

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

window.location.hash="anchor"; 
+0

这是我的问题的真实方法。你好。 – v2p

+2

@xdazz有没有可能解决这个问题,而不使用JavaScript? – Hjulle