Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect to same page to anchor [duplicate]

Tags:

redirect

php

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 ?

like image 734
v2p Avatar asked Aug 31 '12 12:08

v2p


People also ask

How do I redirect an anchor on the same page?

One can use the anchor tag to redirect to a particular section on the same page. You need to add ” id attribute” to the section you want to show and use the same id in href attribute with “#” in the anchor tag.

Can you link to an anchor on another page?

If the anchor you are linking to is on a different page as the link: In the pop-up box, click the Link to dropdown menu and select URL. Enter the full URL of the page followed by the # hashtag symbol, followed by the name of the anchor. Click Insert.

Can you redirect an anchor link?

The server can only redirect the link at page level. It cannot redirect incoming anchor links, because it never sees the anchor part of the URL.

How to prevent page refresh on anchor tag click?

You likely want to put that information elsewhere rather than in the href itself. As you are using jQuery, I'd suggest storing it in an HTML5 data-* attribute (at which point you can put javascript:; into the href to prevent the browser loading a whole new page.


1 Answers

You don't need to redirect the page, just set the window.location.hash.

window.location.hash="anchor";
like image 156
xdazz Avatar answered Oct 04 '22 20:10

xdazz