Hi all,
I have come across the following today...
Code HTML4Strict:<a href="javascript:">image here that has a onclick javascript call</a>
can anybody explain what it means, please?
Thanks
| SitePoint Sponsor |





Hi all,
I have come across the following today...
Code HTML4Strict:<a href="javascript:">image here that has a onclick javascript call</a>
can anybody explain what it means, please?
Thanks


That alone does nothing, but normally javascript: precedes some JavaScript code to indicate that the browser should execute the code instead of treat the href attribute as a URL. It's not the recommended way of attaching JavaScript code to a link.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.





Hi Dan, and thanks for the reply.
The full statement is below...
Code HTML4Strict:<a href="javascript:"> <img src="images/panel_Plus.gif" onclick="changepic()" border="0"/> </a>
What is the recommended way of attaching JS to a hyperlink?
Last edited by Tryst; Apr 30, 2009 at 14:11. Reason: Posted too early.


The link is completely superfluous. Your image will already execute the code on click without the link being there.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.





My bad,
what I posted was coming from an XSL file, and I just noticed that the <a> contains some XSL...
Code XML:<xsl:attribute name="onClick">javascript:document.images['<xsl:value-of select="$source-id"/>'].click()</xsl:attribute>
which is basically assigning an onclick JS event to the <a> which is wrapped around this statement.
Bookmarks