473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with IE6 not registering an event handler

Hi everyone,

I'm trying to dynamically create an image map for a particular image
on my website, and I'm running into an issue where I try to register
the "mouseover" and "mouseout" events for the AREAs of my image map.

Here is an abbreviated version of my code:

------------------------

function createImageMap() {

Â* Â*var divParent = document.getElementById("divParent");

Â* Â*var newMapNode = document.createElement("map");
Â* Â*// set name, id attributes for the newly created map node

Â* Â*for (var i = 0; i < arrayOfPoints.length; i++) {

Â* Â* Â* Â*var mapElement = arrayOfPoints[i];

Â* Â* Â* Â*var areaNode = document.createElement("area");
Â* Â* Â* Â*// set the alt, nohref, shape, coords attributes for the area node

Â* Â* Â* Â*var showMouseOverFunc = function(evt) {
Â* Â* Â* Â* Â* Â*showMouseOver(evt, mapElement);
Â* Â* Â* Â*};

Â* Â* Â* Â*var hideMouseOverFunc = function(evt) {
Â* Â* Â* Â* Â* Â*hideMouseOver(evt);
Â* Â* Â* Â*};

Â* Â* Â* Â*if (areaNode.addEventListener) {

Â* Â* Â* Â* Â* Â*areaNode.addEventListener("mouseover", showMouseOverFunc, false);
Â* Â* Â* Â* Â* Â*areaNode.addEventListener("mouseout", hideMouseOverFunc, false);

Â* Â* Â* Â*} else if (areaNode.attachEvent) {

Â* Â* Â* Â* Â* Â*areaNode.attachEvent("onmouseover", showMouseOverFunc);
Â* Â* Â* Â* Â* Â*areaNode.attachEvent("onmouseout", hideMouseOverFunc);

Â* Â* Â* Â*} else {

Â* Â* Â* Â* Â* Â*areaNode.onmouseover = showMouseOverFunc;
Â* Â* Â* Â* Â* Â*areaNode.onmouseout = hideMouseOverFunc;

Â* Â* Â* Â*}

Â* Â* Â* Â*newMapNode.appendChild(areaNode);

Â* Â*}

Â* Â*divParent.appendChild(newMapNode);
Â* Â*document.getElementById("imgMap").setAttribute(" usemap", "#map");
}

------------------------------

I've tested this in Firefox 2, and it works just fine with the DOM
Level 0 and 2 event models; the events appear to be registered with
their respective area elements and fire when I mouse over and out of
those areas.

However, when I try to run the same code in IE6, the events do not
appear to be registered at all. Â*I've tried sticking an alert() call
inside the functions that are to be called when the events fire and
had no luck. Â*I've also tried using the Level 0 event model (i.e. in
the else-clause) instead of IE's attachEvent() method and had no luck
either.

Can anyone please help me on this issue?

Sincerely,
Andrew

Nov 22 '06 #1
4 1710

Andrew Ip wrote:
var newMapNode = document.createElement("map");
// set name, id attributes for the newly created map node
MSDN says: "The NAME attribute cannot be set at run time on elements
dynamically created with the createElement method. To create an element
with a name attribute, include the attribute and value when using the
createElement method."

Change quoted lines with
var newMapNode = document.createElement("<map name='map1'></map>");

Nov 22 '06 #2
Hi marss,

Thanks for your reply. I tried your suggestion and I don't seem to
have any luck. Do you have any other ideas?

Sincerely,
Andrew
marss wrote:

-- snip --
>
MSDN says: "The NAME attribute cannot be set at run time on elements
dynamically created with the createElement method. To create an element
with a name attribute, include the attribute and value when using the
createElement method."

Change quoted lines with
var newMapNode = document.createElement("<map name='map1'></map>");
Nov 22 '06 #3
Hi marss,

I figured out the problem, which was due to a combination of two
things.

1) IE's inability to set the NAME attribute of a dynamically created
element at runtime, as you pointed out.

2) The problem of IE being really particular about the case-sensitivity
of the img tag's "usemap" attribute when I was setting it in the last
line of my function (IE insists that it should be "useMap").

So, I changed the last line of my function to read:

document.getElementById("imgMap").setAttribute("us emap", "#dynamicMap",
0);

where the 0 means "case-insensitive" for the attribute name, and 1
means "case-sensitive". I only stumbled upon this after inspecting the
DOM tree and trying to figure out why the DOM inspector for the IE
Developer Toolbar was not showing the attributes that I set for the
area element.

For this part of the issue, I found the solution at
(http://www.webmasterworld.com/html/3142618.htm).

Thank you very much for all your help.

Sincerely,
Andrew
Andrew wrote:
Hi marss,

Thanks for your reply. I tried your suggestion and I don't seem to
have any luck. Do you have any other ideas?

Sincerely,
Andrew

Nov 22 '06 #4
Hi.
I have the same issue in IE. But I used useMap attribute name. The
problem in my case was that I had not set id attribute for the map (I
had set only name attribute). It worked with name attribute in Firefox
and Opera, but not in IE.

Nov 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
1
by: cjl | last post by:
Hey all: I'm trying to write a cross-browser (IE and firefox) event handler for the mousewheel. Basically my web app is an image viewer, so if you scroll "down" with the wheel the next image...
2
by: Andrew Banks | last post by:
I've got the following code as part of a C# web form but am having problems calling a command. I create a dataset and put some data on the screen. This works fine. (relevant sample below) ...
3
by: moondaddy | last post by:
C# 2.0 I have declared some event arguments like this: public class ModeStateChangedEventArgs : EventArgs { Gen.DataState myState; public ModeStateChangedEventArgs() { }
6
by: Joseph Geretz | last post by:
I'm porting a C# Outlook Addin originally engineered as a COM Addin over to use VSTO. I've gotten this to the point where my VSTO Addin installs its Menu items and Toolbar buttons when Outlook...
0
by: shapper | last post by:
Hello, I have a custom control where I have a button. I need to raise the event FormSubmited after all the code, in Button_Click, is finished. The problem is when I check FormSubmited in my...
1
by: kaczmar2 | last post by:
I have an ASP.NET page where controls are created dynamically, and I have an issue where one event handler creates another set of controls, and then adds event handlers to those controls. The...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
31
by: Scott M. | last post by:
Am I correct in thinking that because C# doesn't have the "Handles" keyword that VB .NET does, we have to register event delegates manually in C#, whereas in VB .NET using "Handles" takes care of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.