strange event handling problem in IE

Discussion in 'Javascript' started by yb, Nov 14, 2005.

  1. yb

    yb Guest

    Hi,

    In IE I usually check for event objects in event handlers with
    something like:

    handler = function( e ) {
    if( !e ) var e = window.event;
    ....
    }

    I am also using IE 'attachEvent' to register the event handler.
    However, IE (6) passes in an empty 'e' object, and not an undefined
    value. Has anyone had this problem before. I've only noticed it
    recently, and I'm wondering if the windows update changed something in
    IE. I'm now forced to check for both e, and the relevant property,
    e.g. e && e.target

    My IE version is:

    6.0.2900.2180.xpsp_sp2_gdr.050301-1519
    yb, Nov 14, 2005
    #1
    1. Advertising

  2. yb

    web.dev Guest

    yb wrote:
    > Hi,
    >
    > In IE I usually check for event objects in event handlers with
    > something like:
    >
    > handler = function( e ) {
    > if( !e ) var e = window.event;
    > ....
    > }


    Not strange at all. IE has never passed an 'e' object to an event
    handler. Other browsers, such as FireFox do. That is why you check to
    ensure whether or not 'e' is defined, if it's not, used IE's
    window.event to assign it to 'e'.

    > I am also using IE 'attachEvent' to register the event handler.
    > However, IE (6) passes in an empty 'e' object, and not an undefined
    > value. Has anyone had this problem before. I've only noticed it
    > recently, and I'm wondering if the windows update changed something in
    > IE. I'm now forced to check for both e, and the relevant property,
    > e.g. e && e.target
    >
    > My IE version is:
    >
    > 6.0.2900.2180.xpsp_sp2_gdr.050301-1519
    web.dev, Nov 14, 2005
    #2
    1. Advertising

  3. yb

    yb Guest

    My point is that IE *is* passing in the 'e' object.

    I'm getting an e object passed in from IE, so the check

    if( !e ) var e = window.event

    does not assign window.event to e, and all event handling fails.
    The e object passed in is empty with no properties but not undefined
    yb, Nov 14, 2005
    #3
  4. yb

    Robert Guest

    yb wrote:
    > Hi,
    >
    > In IE I usually check for event objects in event handlers with
    > something like:
    >
    > handler = function( e ) {
    > if( !e ) var e = window.event;
    > ....
    > }
    >
    > I am also using IE 'attachEvent' to register the event handler.
    > However, IE (6) passes in an empty 'e' object, and not an undefined
    > value. ...
    >
    > My IE version is:
    >
    > 6.0.2900.2180.xpsp_sp2_gdr.050301-1519


    I have the same version as you, but IE does not pass an empty event
    object for me.
    Reinstall IE? Or maybe there is some other js code that interferes with
    the event.
    Robert, Nov 15, 2005
    #4
  5. yb

    Robert Guest

    web.dev wrote:
    > yb wrote:
    >
    >>Hi,
    >>
    >>In IE I usually check for event objects in event handlers with
    >>something like:
    >>
    >>handler = function( e ) {
    >> if( !e ) var e = window.event;
    >> ....
    >>}

    >
    >
    > Not strange at all. IE has never passed an 'e' object to an event
    > handler.


    He uses attachEvent in which case IE6 does pass an event object.
    Robert, Nov 15, 2005
    #5
  6. yb

    yb Guest

    > He uses attachEvent in which case IE6 does pass an event object.

    What information does this object include? I haven't found anything in
    msdn docs about it.

    Perhaps a bug? I haven't had time to test this further, but I'm pretty
    sure this object was empty.
    yb, Nov 15, 2005
    #6
  7. yb wrote:

    >> He uses attachEvent in which case IE6 does pass an event object.

    >
    > What information does this object include? I haven't found anything in
    > msdn docs about it.


    Have you even looked for it? Documentation is linked as the first hit on
    <http://search.microsoft.com/search/results.aspx?qu=event&View=msdn&st=b&c=4&s=1&swc=4>


    PointedEars
    Thomas 'PointedEars' Lahn, Nov 15, 2005
    #7
  8. yb

    VK Guest

    Robert wrote:
    > yb wrote:
    > > Hi,
    > >
    > > In IE I usually check for event objects in event handlers with
    > > something like:
    > >
    > > handler = function( e ) {
    > > if( !e ) var e = window.event;
    > > ....
    > > }
    > >
    > > I am also using IE 'attachEvent' to register the event handler.
    > > However, IE (6) passes in an empty 'e' object, and not an undefined
    > > value. ...
    > >
    > > My IE version is:
    > >
    > > 6.0.2900.2180.xpsp_sp2_gdr.050301-1519

    >
    > I have the same version as you, but IE does not pass an empty event
    > object for me.
    > Reinstall IE? Or maybe there is some other js code that interferes with
    > the event.


    It is not an empty object. It's the same "event" object you can get as
    global variable.

    Traditionally IE provided event info via automatically created
    contextually global variable "event" and Netscape > Gesko via
    automatically assigned first argument in the event handler. But
    starting IE 6.0.2800 (at least) it implements both ways, so you could
    access event info in IE-way or Gesko-way. Very confusing and dangerous
    actually, but I guess that the intentions were to facilitate developers
    life :) :-(

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">

    <script type="text/javascript">

    function init() {
    document.getElementById('ie').attachEvent('onclick',testIE);
    }

    function testIE(e) {
    alert(e.srcElement.tagName);
    alert(event.srcElement.tagName);
    }

    window.onload = init;
    </script>

    <style type="text/css">
    body {background-color: #FFFFFF}
    var {font: normal 10pt Verdana, Geneva, sans-serif;
    color: #0000FF; text-decoration: underline;
    cursor: hand; cursor:pointer}
    </style>

    </head>

    <body>

    <noscript>
    <p><font color="#FF0000"><b>JavaScript disabled:-</b><br>
    <i><u>italized links</u></i> will not work properly</font></p>
    </noscript>

    <p>
    <var id="ie">Test</var>
    </p>

    </body>
    </html>
    VK, Nov 15, 2005
    #8
  9. yb

    yb Guest

    Sorry my wording was not accurate

    yes, I have looked into the docs, what I meant is I could not find
    information about IE passing in an object into the event handler.

    On further testing, the object seems to be same as window.event, but I
    can't find anything on msdn mentioning that it passing an event object
    to the function as a paramter.
    yb, Nov 15, 2005
    #9
  10. yb

    Robert Guest

    VK wrote:
    > Robert wrote:
    >
    >>
    >>I have the same version as you, but IE does not pass an empty event
    >>object for me.
    >>Reinstall IE? Or maybe there is some other js code that interferes with
    >>the event.

    >
    >
    > It is not an empty object. It's the same "event" object you can get as
    > global variable.


    Did you respond to me or the original poster?
    Because I just said that I do not have an empty object.
    Robert, Nov 16, 2005
    #10
    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. Tony
    Replies:
    2
    Views:
    384
    =?Utf-8?B?cmVjb2lsQGNvbW11bml0eS5ub3NwYW0=?=
    May 24, 2006
  2. Mark Tarver
    Replies:
    22
    Views:
    1,274
    J Kenneth King
    Apr 26, 2009
  3. Peter
    Replies:
    34
    Views:
    1,911
    James Kanze
    Oct 17, 2009
  4. Tony

    Expert advice needed on some strange event handling

    Tony, May 24, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    122
  5. Iñaki Baz Castillo
    Replies:
    1
    Views:
    174
    Iñaki Baz Castillo
    Apr 15, 2008
Loading...

Share This Page