Showing posts with label 25. JavaScript Image Maps. Show all posts
Showing posts with label 25. JavaScript Image Maps. Show all posts

25. JavaScript Image Maps

JavaScript Image Maps

HTML Image Maps
Adding Some JavaScript

An image map is an image with clickable regions

HTML Image Maps

<html>
<body>
<img src = "planets.gif" width="145" height="126" alt="planets" usemap="#planetmap"/>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" target="_blank" alt="sun"/>
<area shape="circle" coords="90,58,3" href="mercur.htm" target="_blank" alt="Mercury"/>
<area shape="circle" coords="124,58,8" href="venus.htm" target=_blank" alt="venus"/>
</map>
</body>
</html>

Adding Some JavaScript

we can add events(that can call a JavaScript) to the <area> tags inside the image map.
The <area> tag supports the
onClick
onDblClick
onMouseDown
onMouseUp
onMouseOver
onMouseMove
onMouseOut
onKeyPress
onKeyDown
onKeyUp
onFocus and
onBlur events

<html>
<head>
<script type="text/javascript">
function writeText(txt)
{
document.getElementById("desc").innerHTML=txt;
}
</script>
</head>
<body>
<img src="planets.gif" width="145" height="126" alt="planets" usemap="#planetmap"/>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" onMouseOver="writeText('The sun and the gas giant planets like Jupiter are by far the latgest objects in our Solar System.')" href="sun.htm" target="_blank" alt="sun"/>
<area shape="circle" coords="90,58,3" onMouseOver="writeText('The planet Mercury is very diffivult to study from the earth because it is always so close to the sun.')" href="mercur.htm" target="_blank" alt="mercur"/>
<area shape="circle" coords="124,58,8" onMouseOver="writeText('Until the 1960's venus was often considered a twin sister to the earth because venus is the nearest planet to us, and because the two plannets seem to share many characteristics.')" href="venus.htm" target="_blank" alt="venus"/>
</map>
<p id="desc"></p>
</body>
</html>

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams