Javascript 图像映射在greasemonkey脚本中不起作用

Javascript 图像映射在greasemonkey脚本中不起作用,javascript,image,map,greasemonkey,area,Javascript,Image,Map,Greasemonkey,Area,我创建了一个greasemonkey脚本,在其中我向网页添加了一个横幅。首先,我从简单的图像开始,工作得很好。然后我想添加一个图像贴图来创建工具栏的效果。脚本执行时加载的页面在firebug中看起来不错,但没有点击。如果我在图像中添加onclick,图像将获得单击。不是这个地区。 感谢您的指导 var input=document.createElement("img"); input.src="http://.../banner_gh.png"; var map = document.cre

我创建了一个greasemonkey脚本,在其中我向网页添加了一个横幅。首先,我从简单的图像开始,工作得很好。然后我想添加一个图像贴图来创建工具栏的效果。脚本执行时加载的页面在firebug中看起来不错,但没有点击。如果我在图像中添加onclick,图像将获得单击。不是这个地区。 感谢您的指导

var input=document.createElement("img");
input.src="http://.../banner_gh.png";

var map = document.createElement("map");
map.name = "barMap";
map.id   = "barMap";

var trialArea = document.createElement("area");

trialArea.shape  = "rect";
trialArea.coords = "675,0,766,50";
trialArea.href   = "https://apps..../.../foo";
trialArea.title  = "Start Trial";
trialArea.alt  = "Start Trial";
trialArea.onclick = startTrial;


map.appendChild(trialArea);
input.useMap = "#barMap";

// inserting the image in the right place in my page
var container = document.getElementById("overview");
container.parentNode.insertBefore(input,container); 


function startTrial()
{
    document.location.href = "https://apps..../.../foo";
}
使用Firefox 17和Greasemonkey 1.11
谢谢

您似乎只是忘记了将地图插入页面。尝试添加

container.parentNode.insertBefore(map,container);

希望有帮助。

因此,这些区域已附加到地图,我们需要确保将地图附加到DOM-谢谢!