By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,380 Members | 3,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,380 IT Pros & Developers. It's quick & easy.

Understanding 'Type mismatch' in IE

P: n/a
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
Jan 6 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Andrew Poulos wrote:
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?


I can't, but there is a bit about this on quirksmode:

http://www.quirksmode.org/blog/archi...notes_a_1.html

(see the heading 'Clear readystatechange!')

Not an explanation, but a workaround and some discussion.
Jan 6 '06 #2

P: n/a
VK

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

Jan 7 '06 #3

P: n/a
VK

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;

Jan 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.