15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

332<br />

MAP.areas<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

image displayed in that IMG element, scripts change the useMap property of the<br />

IMG element object to point to a second MAP that has specifications more suited to<br />

the desk lamp in the second image. Roll the mouse pointer atop the images, and<br />

view the URLs associated with each area in the statusbar (for this example, the<br />

URLs do not lead to other pages).<br />

Another button on the page, however, invokes the makeAreas() function (not<br />

working in IE5/Mac), which creates four new AREA element objects and (through<br />

DOM-specific pathways) adds those new area specifications to the image. If you roll<br />

the mouse atop the image after the function executes, you can see that the URLs<br />

now reflect those of the new areas. Also note the addition of a fourth area, whose<br />

status bar message appears in Figure 6-2.<br />

Listing 22-7: Modifying AREA Elements on the Fly<br />

<br />

<br />

MAP Element Object<br />

<br />

// generate area elements on the fly<br />

function makeAreas() {<br />

document.myIMG.src = “desk3.gif”<br />

// build area element objects<br />

var area1 = document.createElement(“AREA”)<br />

area1.href = “Script-Made-Shade.html”<br />

area1.shape = “polygon”<br />

area1.coords = “52,28,108,35,119,29,119,8,63,0,52,28”<br />

var area2 = document.createElement(“AREA”)<br />

area2.href = “Script-Made-Base.html”<br />

area2.shape = “rect”<br />

area2.coords = “75,65,117,87”<br />

var area3 = document.createElement(“AREA”)<br />

area3.href = “Script-Made-Chain.html”<br />

area3.shape = “polygon”<br />

area3.coords = “68,51,73,51,69,32,68,51”<br />

var area4 = document.createElement(“AREA”)<br />

area4.href = “Script-Made-Emptyness.html”<br />

area4.shape = “rect”<br />

area4.coords = “0,0,50,120”<br />

// stuff new elements into MAP child nodes<br />

if (document.all) {<br />

// works for IE4+<br />

document.all.lampMap.areas.length = 0<br />

document.all.lampMap.areas[0] = area1<br />

document.all.lampMap.areas[1] = area2<br />

document.all.lampMap.areas[2] = area3<br />

document.all.lampMap.areas[3] = area4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!