I can easily traverse the current window while I’m inside the pageLoad function in my extension using content.document, but when I try accessing it in another function, called with setInterval, I can’t access the content.document.
I tried content.document, document.defaultView, window.content.document and basically every other sensible combination I could think of.
please help. thanks.
I got this to work by getting the document object out of an event like so:
The event object is available in any event listener function – for e.g. you may be capturing the document loaded event by doing something like this:
In this example, the onPageLoad function gets an event argument that can be used to fetch the document.
To be able to access the document object elsewhere, set a global variable pointing to that. And if using jQuery, pass this as the optional second argument to the $ function (i.e. the context on which jQuery works).