Welcome to WebmasterWorld Guest from 54.204.92.234

Forum Moderators: incrediBILL

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

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

5+ Year Member



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)

5+ Year Member



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)

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



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

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



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)

WebmasterWorld Senior Member 10+ Year Member



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)

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



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)



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)

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



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)

WebmasterWorld Senior Member 5+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month