Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1609 Can you use an imagemap with onClick?

You are here: irt.org | FAQ | JavaScript | Image | Q1609 [ previous next ]

Yes, as the following shows:

<map name="image-map1">
<area shape="rect" coords="15,15,85,85" href="default.htm"
   onClick="alert('square');return false">
<area shape="rect" coords="93,15,110,85" href="default.htm"
   onClick="alert('rectangle');return false">
<area shape="circle" coords="150,50,35" href="default.htm"
   onClick="alert('circle');return false">
</map>

<img src="image.gif" border=0 width=200 height=100 usemap="#image-map1">

However, there is no need o do this as you can instead use a javascript: schema in the href attribute as follows:

<map name="image-map2">
<area shape="rect" coords="15,15,85,85" href="javascript:alert('square')"
<area shape="rect" coords="93,15,110,85" href="javascript:alert('rectangle')"
<area shape="circle" coords="150,50,35" href="javascript:alert('circle')"
</map>

<img src="image.gif" border=0 width=200 height=100 usemap="#image-map2">

©2018 Martin Webb