Understanding 'Type mismatch' in IE

Discussion in 'Javascript' started by Andrew Poulos, Jan 6, 2006.

  1. I have a constructor with this IE specific code in it:

    this.doc.onreadystatechange = this.ready;

    in a subsequent method I have:

    alert(this.doc.readyState);
    this.doc.onreadystatechange = null;

    The alert displays 4 so it 'must' be recognising this.doc yet IE tells
    me that the next line has Error: Type mismatch.

    Could someone please explain why the error is occurring?

    Andrew Poulos
    Andrew Poulos, Jan 6, 2006
    #1
    1. Advertising

  2. Andrew Poulos

    VK Guest

    Andrew Poulos wrote:
    > I have a constructor with this IE specific code in it:
    >
    > this.doc.onreadystatechange = this.ready;
    >
    > in a subsequent method I have:
    >
    > alert(this.doc.readyState);
    > this.doc.onreadystatechange = null;
    >
    > The alert displays 4 so it 'must' be recognising this.doc yet IE tells
    > me that the next line has Error: Type mismatch.
    >
    > Could someone please explain why the error is occurring?


    Some IE versions do not allow you to "kill" event listener in such way.
    Overall it's a very rude habit :)

    Use instead:

    this.doc.attachEvent('onreadystatechange', myListener);
    ....
    this.doc.detachEvent('onreadystatechange', myListener);

    and
    addEventListener / removeEventListener respectively for Firefox
    VK, Jan 6, 2006
    #2
    1. Advertising

  3. Andrew Poulos

    VK Guest

    Andrew Poulos wrote:
    > I have a constructor with this IE specific code in it:
    >
    > this.doc.onreadystatechange = this.ready;
    >
    > in a subsequent method I have:
    >
    > alert(this.doc.readyState);
    > this.doc.onreadystatechange = null;
    >
    > The alert displays 4 so it 'must' be recognising this.doc yet IE tells
    > me that the next line has Error: Type mismatch.
    >
    > Could someone please explain why the error is occurring?
    >
    > Andrew Poulos


    Or (much less academical but more universal and simple I guess) use an
    event dumper:

    function foo() {
    /* NOP */
    }
    ....
    obj.onreadystatechange = someUsefulFunction;
    ....
    obj.onreadystatechange = foo;
    VK, Jan 6, 2006
    #3
    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. data type mismatch error

    , Aug 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    628
    Karl Seguin
    Aug 10, 2005
  2. type mismatch error

    , Aug 12, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,344
    Kevin Spencer
    Aug 12, 2005
  3. Artie Gold

    Re: type mismatch

    Artie Gold, Feb 28, 2004, in forum: C Programming
    Replies:
    0
    Views:
    390
    Artie Gold
    Feb 28, 2004
  4. Harry Pehkonen

    win32com, string array --> Type mismatch?

    Harry Pehkonen, Aug 8, 2003, in forum: Python
    Replies:
    2
    Views:
    1,854
    Harry Pehkonen
    Aug 11, 2003
  5. programmingzeal
    Replies:
    0
    Views:
    1,098
    programmingzeal
    May 6, 2012
Loading...

Share This Page