Instanceof Fails In Iframe
The following code returns true. Doing the same in an
Solution 1:
This is because:
1) Element
is actually window.Element
2) In JS there is no such thing as a "class". Everything (almost) is an object. So instanceof checks for Prototype ancestry. When you ask is some DOM node instanceof Element
you could kind of translate this to someDOMNode.prototype === Element
.
3) window.Element !== document.querySelector('iframe').contentWindow.Element
!!!
This will log true
as expected:
console.log(iframe.createElement('script') instanceofdocument.querySelector('iframe').contentWindow.Element);
Post a Comment for "Instanceof Fails In Iframe"