【问题标题】:Image map not working in greasemonkey script图像映射在greasemonkey脚本中不起作用
【发布时间】:2013-12-06 19:16:05
【问题描述】:

我创建了一个greasemonkey 脚本,在其中向网页添加横幅。首先,我从普通图像开始,效果很好。然后我想添加一个图像映射来创建工具栏的效果。页面加载,脚本执行,在萤火虫中看起来不错,但没有获得点击。如果我向图像添加 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 谢谢

【问题讨论】:

    标签: javascript image map greasemonkey area


    【解决方案1】:

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

    container.parentNode.insertBefore(map,container);
    

    希望对你有帮助。

    【讨论】:

    • 因此这些区域已附加到地图上,我们需要确保将地图附加到 DOM - 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 2014-05-18
    • 2012-04-25
    • 1970-01-01
    • 2014-04-21
    相关资源
    最近更新 更多