user2311979
user2311979

Reputation: 35

OnMouseOver feature not working

I've made an image map for an image with social links on it. However, when I changed the links to open in a new window I lost my OnMouseOver cursor. This is all in JavaScript by the way. I've tried to put it in, but it doesn't seem to be working anywhere. When I click on the images they do go to a new window, but the cursor doesn't change so the user doesn't know they are on a link. Code is below.

Any ideas on how to get this back would be great. Thank you!

document.getElementById('topdiv').innerHTML = "<img border=\"0\" style=\"padding-right: 10px;\" src=\"../images/social_hor.png\" usemap=\"#socialmap\"><map name=\"socialmap\"><area shape=\"rect\" coords=\"320,0,365,50\" onClick=\"window.open('https://www.facebook.com/NCHSoftware')\" OnMouseOver='this.style.cursor='pointer';'><area shape=\"rect\" coords=\"375,0,420,50\" onClick=\"window.open('https://plus.google.com/+nchsoftware')\"><area shape=\"rect\" coords=\"425,0,470,50\" onClick=\"window.open('https://twitter.com/nchsoftware')\">"

Upvotes: 0

Views: 163

Answers (1)

Xotic750
Xotic750

Reputation: 23492

So I've translated that HORRIBLE line that you posted in your question (I guess that's why people haven't given your question any consideration) and I have come up with this example for you, of course you will still need to implement it correctly in your page.

CSS

myImage {
    padding-right: 10px;
}

HTML

<div id="topdiv"></div>

Javascript

var topdiv = document.getElementById('topdiv'),
    map,
    tempVar;

function area1() {
    alert("you clicked in area1");
}

function area2() {
    alert("you clicked in area2");
}

function area3() {
    alert("you clicked in area3");
}

function pointerOn(evt) {
    evt.target.style.cursor = "hand";
}

function pointerOff(evt) {
    evt.target.style.cursor = "auto";
}

map = document.createElement("map");
map.name = "socialmap";

tempVar = document.createElement("area");
tempVar.shape = "rect";
tempVar.coords = "0,0,99,50";
tempVar.href = "#";
tempVar.addEventListener("click", area1, false);
tempVar.addEventListener("mouseover", pointerOn, false);
tempVar.addEventListener("mouseout", pointerOff, false);
map.appendChild(tempVar);

tempVar = document.createElement("area");
tempVar.shape = "rect";
tempVar.coords = "100,0,199,50";
tempVar.href = "#";
tempVar.addEventListener("click", area2, false);
tempVar.addEventListener("mouseover", pointerOn, false);
tempVar.addEventListener("mouseout", pointerOff, false);
map.appendChild(tempVar);

tempVar = document.createElement("area");
tempVar.shape = "rect";
tempVar.coords = "200,0,299,50";
tempVar.href = "#";
tempVar.addEventListener("click", area3, false);
tempVar.addEventListener("mouseover", pointerOn, false);
tempVar.addEventListener("mouseout", pointerOff, false);
map.appendChild(tempVar);

topdiv.appendChild(map);

tempVar = document.createElement("img");
tempVar.className = "myImage";
tempVar.src = "http://i860.photobucket.com/albums/ab165/ATnightshift/image001.gif";
tempVar.useMap = "#socialmap";
topdiv.appendChild(tempVar);

On jsfiddle

Upvotes: 1

Related Questions