Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari anchors on links not working

Tags:

html

xhtml

safari

My html anchor is as follows.

<a name="template-8"/>
<h4 class="template" id="template-8">A title</h4>

As far as I know the browser should skip to the element with a matching name or id attribute.

When I type in the url http://my.site.com/templates#template-8 safari jumps down the page as expected.

However when linking as below the anchor does nothing. Chrome, Opera, IE7 and Firefox all work.

<a href="http://my.site.com/templates#template-8">A link</a>

Safari is version 5.0, could this be a safari bug?

like image 287
Keyo Avatar asked Jun 11 '10 05:06

Keyo


2 Answers

The problem was I had a redirect header in the page I was linking to.

Opera, IE, Chrome, Firefox will carry over the anchor to the new page. However safari loses the anchor on the redirect.

If you are having trouble with safari anchors disable any redirects.

like image 112
Keyo Avatar answered Sep 28 '22 10:09

Keyo


For me, I simply had to change

http://domain.com/page#myanchor 

to

http://domain.com/page/#myanchor
like image 20
Jase Whatson Avatar answered Sep 28 '22 10:09

Jase Whatson