You are here: Re: onClick() on an anchor that doesn't force the page to jump to the top? « HTML « IT news, forums, messages
Re: onClick() on an anchor that doesn't force the page to jump to the top?

Posted by nice.guy.nige on 10/06/07 11:42

While the city slept, Aaron Freeman (aaronf@gmail.com) feverishly typed...

> I have a javascript swap image funciton that's called when a user
> clicks on an image wrapped by an anchor. The anchor points to "#",
> but the problem is that the image is below the fold, and when the
> user clicks on the image, the image swaps but the page links to "#"
> and scrolls the page to the top.

[...]

That is because you have fallen into the trap of having to use <a href...>
to gather your onclick event, but you think it doesn't need to point to a
file, so you erroneously use "#" as the URI assuming that goes nowhere.
Unfortunately it usually goes to the top of the page.

The big problem you have is that you aren't providing any support for those
users who have javascript turned off or even unavailable. You should make
the image available to the user regardless. As others have said, you could
link direct to the image, or I have a reasonably elegant solution here if
php is available to you (or, it could of course be adapted to another
server-side language): http://www.nigenet.org.uk/stuff/thumbtastic/ - This
displays a main image and a series of thumbnails underneath. It uses
javascript to change the main image according to which thumbnail was clicked
(and - where available - also changes the alt-text). If javascript is not
available to the end user, the page is reopened and php sets the main image
to the one selected.

Hope that helps.

Cheers,
Nige

--
Nigel Moss http://www.nigenet.org.uk
Mail address will bounce. nigel@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация