DOM-Elementsを使用してマップエリアを持つオブジェクトを作成しました。今は、ある領域(座標)をクリックすると関数を実行したいと思います。私はまた、それがクリックされているかどうかを確認する必要があると思いますか?また、私はDOM要素に何かがないと思う。オブジェクト内の領域をクリックするときに関数を実行する方法は?
var _images = { //Object-MapArea
start: {
path: 'start.jpg',
areas: [{
coords: '18,131,113,140',
text: 'Homepage',
onclick: doSomething, // ???
}]
},
}
// ..... there is more code not shown here
//Creating DOM-Elements
var areaElem = document.createElement('AREA');
// Set attributes
areaElem.coords = area.coords;
areaElem.setAttribute('link', area.goto);
areaElem.setAttribute("title", area.text);
areaElem.setAttribute("shape", "rect");
areaElem.onclick = doSomething; ? ? ?
if (element.captureEvents) element.captureEvents(Event.CLICK); ? ? ?
areaElem.addEventListener('click', onArea_click);
_map.appendChild(areaElem);
function doSomething(e) {
if (!e) var e = window.event
e.target = ... ? ?
var r = confirm("Data will get lost!");
if (r == true) {
window.open("homepage.html", "_parent");
} else {
window.open(" ", "_parent"); // here I want to stay in the current pictures. I mean the current object map area. But how can I refer to it so it stays there ?
}
}
ありがとう。あなたは私のヒーローです=)このエリアをクリックすると、確認のメッセージが表示されます。はいを押すと、例goto: 'asdf'のような領域にリダイレクトされますので、asdfに進む必要があります。他の領域にはNo(画像) – Emloy
okですので、areaClickedを取得した直後に要素のリンク属性を取得しますそれはonArea_click関数で行われました) –
さらに私は別の質問があります。 http://stackoverflow.com/questions/38501885/how-can-i-use-object-properties-for-other-object-values-inside-the-same-object – Emloy