ie8 javascript "new function" behavior

  • Thread starter Thread starter Doug Heeren
  • Start date Start date
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,
 
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.
 
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.
 
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.
 
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.
 
Back
Top