On 6/5/15 7:58 AM, Marcello Stanisci wrote:
> The problem is how to check whether a document is an instance of HTMLDocument in
> the code of a bootstrapped extension.
If you're OK with not including synthetic image documents, the simplest
thing might be:
Object.prototype.toString.call(doc) == "[object HTMLDocument]"
If you want to include them, you could do that explicitly by also
testing for "[object ImageDocument]", of course.
Alternately, if you only care about documents in a window, then you
could do:
doc.defaultView && doc instanceof doc.defaultView.HTMLDocument
(or skip the doc.defaultView test if you know it has one).
It's also possible that doing this:
doc instanceof Components.interfaces.nsIDOMHTMLDocument
would work, thought I personally would prefer it if you used one of the
other things so wecan work on killing off nsIDOMHTMLDocument. ;)
-Boris