Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Advanced
Aug 31, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Making the Image OnClick Work in Both Browsers

Since the introduction of DHTML and client-side scripting, developing Internet applications can be a real challenge. If you don't have the luxury of a "pure" Internet Explorer environment, there's a good chance that onclick event you coded will not fire in Netscape. With Netscape, the image (<IMG>) tag does not recognize the onclick event the way that IE does. To get around this problem, you can add an AreaMap to the HTML. If the browser is IE, the onclick event will fire from the IMG object but ignores the AreaMap. On the flip side, Netscape will fire the HREF code and ignore the onclick of the image object:
<IMG name="pswd" SRC="sendpswd.gif"  border="0" usemap="#pswd" style="cursor:hand" 	onclick="reqpswd()">
<map name="pswd">
	<area href="javascript:reqpswd()" shape="default">
If you're using Netscape, it will understand what to do with this line of code: <area href="javascript:reqpswd()" shape="default"> and will execute the procedure named "reqpswd()". On the other hand, IE will respond to the onclick event and execute the same procedure. The end result is the same from the two different browsers. It also avoids having to put conditional statements in your HTML for browser checking.
Mike Gasperino
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date