Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #26019

Re: Dynamically assign image map values?

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: Dynamically assign image map values?
Date 2014-10-29 10:25 +0200
Organization A noiseless patient Spider
Message-ID <m2q89q$c5m$1@dont-email.me> (permalink)
References <m2q62u$u73$1@news.albasani.net>

Show all headers | View raw


2014-10-29 9:47, Tuxedo wrote:

> For example, if the page loads first including a usemap object:
> <img src="mymap.jpg" usemap="#mymap" id="hello">
> (without any href values).

An <img> element does not have an href attribute at all. If you mean 
that there is no <map> element named "mymap", then you would have a 
syntax error.

> Thereafter, and once the page has already loaded, assign by a JS function
> its href dom values, as if the following becomes present in the html:
> <map name="mymap">
> <area shape="rect" coords="20,20,60,220" href="rect.html">
> </map>

You can add a <map> element dynamically, yes. It would however be more 
logical to have it included statically, containing a single <area> 
element that corresponds to the entire image and has an href attribute 
pointing to a document explaining that the page does not work without 
JavaScript enabled, or something like that, or just with no action if 
that's more suitable. Then you can dynamically replace that <area> by a 
set of real <area> elements, if that's what you need.

> Or, initially load the image as a normal image (<img src="mymap.jpg"
> id="hello">) and thereafter make it a usemap="#.. and add the linked
> coordinates.

Well, that's possible too, and perhaps better.

> Can this be done?

Yes.

> If so, what is the most direct way?

It depends on your definition for "direct". In the latter approach, 
using just document.createElement to create the <area> elements and 
adding them with the <map> element's appendChild method sounds direct to me.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 08:47 +0100
  Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-29 10:25 +0200
    Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 13:00 +0100
      Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 19:28 +0100
        Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 21:50 +0100
          Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 07:51 +0200
            Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-30 09:44 +0100
          Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-30 18:35 +0100
            Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 19:57 +0200
              Re: Dynamically assign image map values? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-30 19:46 +0100
                Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 20:57 +0200
                Re: Dynamically assign image map values? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-30 21:26 +0100
                Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 22:58 +0200
              Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-30 20:52 +0100
                Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 22:23 +0200

csiph-web