I'm developing an extension for FireFox. The extension adds event listener to "appcontent" element on "load" event. How to determine the event came from the main document of the tab? At the moment all events from different elements of the page come (for example image and even the extension document if it fires one). I would like to exclude all the cases, including frames, iframe and so on, only the url typed in the location bar.
A:
Can you compare event.srcElement.ownerDocument
the main page document? You could also use the .location.href properties. Quick and dirty example:
//- on event
var doc = event.srcElement.ownerDocument;
if (doc && (doc.location.href == currentUrl))
runFunction();
Andy E
2009-12-17 10:14:48
A:
Have a look at originalTarget
and explicitOriginalTarget
attributes of event
object. https://developer.mozilla.org/en/DOM/event.originalTarget
Use it as something like:
if(event.explicitOriginalTarget == theHookedObject) {
// do your stuff
}
Where theHookedObject
is the object to which you've attached your listener to.
xk0der
2009-12-17 10:23:56
+1
A:
Just an answer for those who gave points to the question itself and who might find the question through the search.
The task is solved with the line
if (Event.originalTarget == content.document)
worked for me.
Found in some newsgroup
Maksee
2009-12-18 10:30:08
Note, that this restricts you to the currently visible page. I.e. if a background page finishes loading, it will not pass this check.
Nickolay
2009-12-28 19:43:05
Nickolay
2009-12-28 20:05:21