ie8 javascript "new function" behavior

D

Doug Heeren

I have an application that uses a custom ajax library to inject xml generated
by a control using an httphandler. What I've run into is a problem with
javascript as an attribute value.

The following line of code used to work
e.setAttribute(attributes.nodeName, new Function(attributes.nodeValue));
where attributes.nodeName = "onclick" and attributes.nodeValue =
"jsfunction('value'); return false;"

ie8 in standards mode renders this as onclick="[object]" and this just
throws a javascript error when the user clicks on it
ie8 in compatibility mode renders this correctly as
onclick="jsfunction('value'); return false;" This works correctly for the
user.

Can anyone point me in the right direction in javascript to
1) identify ie8 as the browser
2) modify the line of code in error to something that works?

TIA,
 
M

Martin Honnen

Doug said:
The following line of code used to work
e.setAttribute(attributes.nodeName, new Function(attributes.nodeValue));
where attributes.nodeName = "onclick" and attributes.nodeValue =
"jsfunction('value'); return false;"

Can anyone point me in the right direction in javascript to
1) identify ie8 as the browser
2) modify the line of code in error to something that works?


You can simply do
e[attributes.nodeName] = new Function(attributes.nodeValue);
no need to try to identify IE 8.
 
D

Doug Heeren

That woks perfectly. What is the difference between the two? On the surface
they appear to do the same.
--
Doug Heeren
Project Manager
Annett Holdings, Inc.
(515) 256-2918


Martin Honnen said:
Doug said:
The following line of code used to work
e.setAttribute(attributes.nodeName, new Function(attributes.nodeValue));
where attributes.nodeName = "onclick" and attributes.nodeValue =
"jsfunction('value'); return false;"

Can anyone point me in the right direction in javascript to
1) identify ie8 as the browser
2) modify the line of code in error to something that works?


You can simply do
e[attributes.nodeName] = new Function(attributes.nodeValue);
no need to try to identify IE 8.
 
M

Martin Honnen

Doug said:
That woks perfectly. What is the difference between the two? On the surface
they appear to do the same.

Do they? No,
e[e[attributes.nodeName] = ...
sets a property.
e.setAttribute([attributes.nodeName], ...)
is supposed to set an attribute but is broken by design in IE before
version 8.
 
D

Doug Heeren

That makes sense. I appreciate this very much!

--
Doug Heeren
Project Manager
Annett Holdings, Inc.
(515) 256-2918


Martin Honnen said:
Doug said:
That woks perfectly. What is the difference between the two? On the surface
they appear to do the same.

Do they? No,
e[e[attributes.nodeName] = ...
sets a property.
e.setAttribute([attributes.nodeName], ...)
is supposed to set an attribute but is broken by design in IE before
version 8.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top