Understanding 'Type mismatch' in IE

A

Andrew Poulos

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
 
V

VK

Andrew said:
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
 
V

VK

Andrew said:
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;
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top