I have an HTML page that has several anchors on it:
<h4>Anchor 1</h4><a name="anchor1"></a>
<p>blah blah</p>
<h4>Anchor 2</h4><a name="anchor2"></a>
<p>blah blah</p>
<h4>Anchor 3</h4><a name="anchor3"></a>
<p>blah blah</p>
Then, I have a PHP array to relative paths:
$anchor_array = array(
'site/path/#anchor1' => 'Anchor 1',
'site/path/#anchor2' => 'Anchor 2',
'site/path/#anchor3' => 'Anchor 3',
);
Each site/path/
has an index.php
file inside so using .htaccess
I'm able to use a link like this:
site/path/
This works fine, but when I add the anchor to it (eg, site/path/#anchor1
) I get sent to the correct page, but not to the anchor location, just to the top of page.
What am I missing?
** EDIT **
After taking Salman A's advice, I was able to get 2/3 anchors to work properly. But one was still causing me trouble. I thought, perhaps, the browser is confusing the anchor name I have specified with something else. So I did a test and changed the anchor from anchor1
to the_anchor1
(actually, I changed it from history
to our-history
) and it works now.
Is there a reason using history
as anchor name is bad?
Regarding:
- result looks like this:
http://localhost/site/path/#anchor1/
- viewing source results in this:
You have a trailing slash in the hash portion of your URL. The browser will look for a named anchor with name=anchor1/
(or id=anchor1/
) which is not there obviously. Locate where the trailing slash is coming from and remove it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.