[Greasemonkey] Image maps in JS

Edward Lee edilee at gmail.com
Tue Apr 19 21:11:23 EDT 2005


On 4/19/05, Geir Thorud <geir.thorud at chello.no> wrote:
> I want to use GM to modify an image map, i.e.
> add new areas, change the location of existing areas
> and add JS functions to be executed when an area is
> clicked.

I haven't played around with map/areas too much, but taking a quick
look through the dom inspector.. you should be able to access the map
and its area tags just like any other node. The area nodes have
attributes that you'll probably want to modify such as coords and
href. For the javascript, you can either set the href to be
"javascript:..." or add an onclick eventlistener to the area.

var a = document.createElement('area');
a.coords = '0,0,100,100';
a.href = '/';
document.getElementsByTagName('map')[0].appendChild(a);

Assuming the map is already there, that code will create a new area in
the upper left corner that links back to the root.

-- 
Ed


More information about the Greasemonkey mailing list