Welcome to WebmasterWorld Guest from 50.17.114.227

Forum Moderators: incrediBILL

Message Too Old, No Replies

href="#" not linking to top of page in safari 3

     
6:34 pm on Aug 18, 2009 (gmt 0)

New User

5+ Year Member

joined:Aug 15, 2009
posts: 19
votes: 0


Hi guys,
I'm using a simple <a href="#">top of page</a> to lead users back to the top of the page(this is part of a FAQ page).

I'm not sure why its not working on safari 3, I've tested it on IE, firefox and safari 4 and it works fine.

Please help.

8:07 pm on Aug 18, 2009 (gmt 0)

New User

5+ Year Member

joined:Aug 15, 2009
posts: 19
votes: 0


I added this to the top of the page:
<body>
<a name="top"></a>

Then changed my href's to:
<a href="#top">top of page</a>

This works :)

8:38 pm on Aug 18, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
posts:37301
votes: 0


That's exactly right - I'm glad you figured it out.
10:19 pm on Aug 23, 2009 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 31, 2003
posts:9063
votes: 2


A simpler method (and much better than using the old-style
name
attribute on an anchor) is to use an
id
attribute on the
body
element:

<body id="top">

The links will work the same:

<a href="#top">top of page</a>
3:47 am on Aug 24, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 29, 2003
posts:1676
votes: 0


A simpler method (and much better than using the old-style name attribute on an anchor) is to use an id attribute on the body element:

<body id="top">

My vote for tip of the day.

W3C - Anchors [w3.org]

The destination anchor of a link may be an element within an HTML document. The destination anchor must be given an anchor name and any URI addressing this anchor must include the name as its fragment identifier.

Destination anchors in HTML documents may be specified either by the A element (naming it with the name attribute), or by any other element (naming with the id attribute).

I admit to having a lot of old websites or pages that still have a lot of:

<p>
<a name="bad-example">
</a>
</p>

but I also still run into a lot of people that still using this sort of markup.

id="best-practice" is my friend.

Used to have to wrap the fragment identifiers in a <p> because pages wouldn't validate if one just slid the <a> in the page; though they worked.

10:04 pm on Aug 24, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


This thread really needs to be linked to P1R's Fragment Identifers [webmasterworld.com] thread . . . "named anchors" or fragment identifiers can be attached to any id'ed element.
10:10 pm on Aug 24, 2009 (gmt 0)

Senior Member

joined:Jan 27, 2003
posts:2534
votes: 0


I think the reason for the <a name> hangover is that it was not widely supported when fragment identifiers were introduced. Thus, the non-ideal situation of a new element just for the sake of a skiplink that was widely compatible.
10:51 pm on Aug 24, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member suzyuk is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Oct 1, 2002
posts:5199
votes: 0


apparently linking to #top,
<a href="#top">link to top</a>
- works without even attaching (name=top or ID = "top") to any element, via ID or name ;)

it's a kinda special reserved name thing...

11:33 pm on Aug 24, 2009 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member 10+ Year Member

joined:June 18, 2005
posts:1692
votes: 3


Some browsers link to the top of the page by default if you have <a href="#"></a>, so if it doesn't find #top, maybe it just fall back to the default # behavior.