ie8 javascript "new function" behavior

Discussion in 'ASP .Net' started by Doug Heeren, Jun 17, 2009.

  1. Doug Heeren

    Doug Heeren Guest

    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 Heeren
    Project Manager
    TMC Transportation
    (515) 256-2918
     
    Doug Heeren, Jun 17, 2009
    #1
    1. Advertising

  2. Doug Heeren wrote:

    > 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.


    --

    Martin Honnen --- MVP XML
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jun 17, 2009
    #2
    1. Advertising

  3. Doug Heeren

    Doug Heeren Guest

    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" wrote:

    > Doug Heeren wrote:
    >
    > > 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.
    >
    >
    > --
    >
    > Martin Honnen --- MVP XML
    > http://msmvps.com/blogs/martin_honnen/
    >
     
    Doug Heeren, Jun 17, 2009
    #3
  4. Doug Heeren wrote:
    > 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.


    --

    Martin Honnen --- MVP XML
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jun 17, 2009
    #4
  5. Doug Heeren

    Doug Heeren Guest

    That makes sense. I appreciate this very much!

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


    "Martin Honnen" wrote:

    > Doug Heeren wrote:
    > > 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.
    >
    >
    > --
    >
    > Martin Honnen --- MVP XML
    > http://msmvps.com/blogs/martin_honnen/
    >
     
    Doug Heeren, Jun 17, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shsha
    Replies:
    0
    Views:
    270
    shsha
    Mar 6, 2008
  2. Qu0ll
    Replies:
    5
    Views:
    560
  3. Jeremy J Starcher
    Replies:
    7
    Views:
    759
  4. dorayme
    Replies:
    29
    Views:
    1,174
  5. cecile

    ie8!=ie8

    cecile, May 24, 2010, in forum: Javascript
    Replies:
    2
    Views:
    205
    David Mark
    May 24, 2010
Loading...

Share This Page