Reputation: 3692
I have the following code in javascript (firefox extension)
var body;
var Test = {
initializeBody: function(e) {
if (!e.originalTarget.defaultView.frameElement) {
body = e.target.ownerDocument.getElementsByTagName('body')[0].cloneNode(true);
}
}
}
window.addEventListener("DOMContentLoaded", function(e) { Test.initializeBody(e); }, false);
when I want to use body
variable in another function Error console
writes that body is undefined
. I understand that not all firefox pages have body
tag defined, but it writes this message even if I load http://www.google.com
Do you know what is wrong?
thank you
Upvotes: 0
Views: 5750
Reputation: 15351
If body
is undefined, I'd assume that nothing was assigned to it, probably because !e.originalTarget.defaultView.frameElement
expression evaluates to false
. What's that condition for?
Upvotes: 0
Reputation: 3519
you need to use document.body for accessing the body tag of a document
Upvotes: 3