Re: Mix of javascript, image and href

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

Edwin Knoppert wrote:
I have an asp.net imagebutton with a clickevent.
I have enclosed an anchor around the image and a small text.
If i click the image the event is executed (while the href of the anchor shows in the statusbar)

If the user clicks the image or the text beneat it it should do the same, executing the image asp.net server event.

I can manage this fine using javascript but the href must contain a character to get the mousehand.
I used # but than the window scrolls to top, postback happens and the scroll position remains to top.

You must return false in the event handler to avoid executing the HREF.

Additionally, the best practice is not to use "#" in the HREF but rather a link to a page explaining why this functionality doesn't work without JavaScript, or linking to a basic page showing the same content, but without the additional functionality provided by JavaScript.

Example:
<a href="nojs.html" onclick="myFunction();return false;">
<img src="..." /></a>

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
.



Relevant Pages

  • Re: Mix of javascript, image and href
    ... I have enclosed an anchor around the image and a small text. ... You must return false in the event handler to avoid executing the HREF. ... JavaScript, or linking to a basic page showing the same content, but ... without the additional functionality provided by JavaScript. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Mix of javascript, image and href
    ... The anchor executes the js code and shows an alert, after that the scroll ... I have enclosed an anchor around the image and a small text. ... You must return false in the event handler to avoid executing the HREF. ... JavaScript, or linking to a basic page showing the same content, but ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Virus from web surfing
    ... explicit "actual executing some file". ... I understand about scripts being downloaded and running on the client side and I understand that if Javascript does something on the client ... While some Javascript release in a browser could have a bug in it which allowed such intrusion I would strongly imagine that this would have been fixed and that every browser one uses, if one keeps the browser up-to-date, will pick up such a fix. ...
    (alt.comp.anti-virus)
  • Re: onClick() on an anchor that doesnt force the page to jump to the top?
    ... clicks on an image wrapped by an anchor. ... users who have javascript turned off or even unavailable. ... displays a main image and a series of thumbnails underneath. ... the page is reopened and php sets the main image ...
    (alt.html)
  • Re: new window with javascript
    ... here it is a SIMPLE code based in this page´s example, an "anchor" ... tied up to a javascript function ... ... I need to have control of the new window (v.g: ...
    (comp.lang.vrml)