...

View Full Version : anchor tag not working in IE



sigmundsquirrel
12-27-2006, 04:31 AM
Should be simple. Ha, should be! This works in everything (Mac and PC, Safari and Firefox) but not IE. I've got a simple "back to top" link at the bottom of my page to bring you back to an anchor tag at the top of the page.

I've got

<a id="top"></a>

at the top of the page, and

<a href="#top">back to top</a>

at the bottom.

You can see the problem at http://www.poddesign.com/myvu2/index.html?category=5

Only tricky thing is that this is within a frameset. Does the anchor tag not work in IE in a frame? Also, I used to have <a name="top"> but was told that name was depracated in favor of id.

Thanks,
sigmundquirrel

TripperTreats
12-27-2006, 06:33 AM
Actually I think the whole id/name issue is your problem in IE.

http://www.w3.org/TR/html401/struct/links.html

Try changing it back to having a name attribute, and I think it will work.

Uzair
12-27-2006, 12:51 PM
Give a TARGET attribute in anchor tag.

codingmasta
12-27-2006, 02:46 PM
link for "a name"


<a name="#top">

Link for back to top:


<a href="#top">

#top and top are different so it doesn't match it...

sigmundsquirrel
12-27-2006, 10:21 PM
Thanks everyone!

This link from TripperTreats to the W3C site had the answer:

http://www.w3.org/TR/html401/struct/links.html

It turns out that although all browsers SHOULD be able to find an anchor tag like <a name="top"></a>, some (meaning IE) can't find it if it's empty like that (no character content between the tags).

So I changed it to <a name="top>&nbsp;</a> with a non-breaking space between the tags, and it's working now. BTW, "name" and "id" are both valid...

thanks,
sigmundsquirrel

Arbitrator
12-27-2006, 10:45 PM
It turns out that although all browsers SHOULD be able to find an anchor tag like <a name="top"></a>, some (meaning IE) can't find it if it's empty like that (no character content between the tags). In such cases, it should be fairly obvious that you donít need the anchor element at all. Why not just put an ID on the body tag or some other tag at the top of your document and reference that?


So I changed it to <a name="top>&nbsp;</a> with a non-breaking space between the tags, and it's working now. BTW, "name" and "id" are both valid...Theyíre both valid in general, but the name attribute has been deprecated (http://www.w3.org/TR/xhtml11/xhtml11.html#a_changes) on the anchor element in XHTML 1.1. In general, the ID attribute should be used unless some functionality only available to names is needed; in those cases itís good practice to use both.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum