[thelist] Javascript onclick doesn't fire?
Stephen Rider
evolt_org at striderweb.com
Tue Aug 22 14:08:09 CDT 2006
Hi --
I've been learning DOM scripting with Javascript with the help of a
excellent book ("Dom Scripting" by Jeremy Keith)
With the goal of separating content from behavior, I've been removing
hard-coded onclicks from various pages. I have a page with a client-
side imagemap (actually several, but I'll simplify for
descriptions...) -- the various links on the imagemap link to JPGs.
I've removed the hard-coded onload attributes in the imagemap's area
tags, and now use DOM scripting to iterate through the area tags and
add the appropriate onclicks on page load.
Works great in Firefox. IE 6 acknowledges that the onclick attribute
has been applied to the tags, but it doesn't actually "fire" when the
link is clicked.
There's nothing wrong with the script the onclick points to. It
works fine in IE if I hard-code the onclick. The code that adds the
onclick attribute is working as well -- I know because I tested it
using an alert that displays the content of the tag's onclick
attribute. The alert pops up in IE, with the correct content, when
the page loads.
But when I click on the links, the bare images come up, instead of
the results of the javascript.
Does anyone have any idea what might be happening here? Does IE
ignore onclicks that are themselves written by javascript?
Here is one of the pages in question:
<http://tinyurl.com/rtryv>
And example of the onclick that is added:
onclick="openCamHR(360,270,640,480,this.href,'View 1 - ' + this.alt);
return false;"
Works in Firefox.
Works in IE 6 when hard-coded.
Doesn't even try when added via the DOM in IE 6 (it _is_ added, it
just doesn't get triggered, apparently)
Thanks in advance!
Stephen Rider
More information about the thelist
mailing list