Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I use load() event within onLocationChange() event?

7 views
Skip to first unread message

Li Hong

unread,
Dec 22, 2009, 12:35:00 AM12/22/09
to dev-ext...@lists.mozilla.org
Q1:How can I get this URL?

Another way to describe my problem above is that I want to capture
URL/Title/H1 of every URL going to be opened in new tab or existing tab.
OnLoc routine only helps to capture those info of LOADED tab, ie the page is
loaded so the HTML DOM tree has been populated. But for url being opened in
new Tab, onLoc is not helpful as when onLOc is called, the DOM tree hasn't
been populated so getElementsByTagName('title') is null.

So I can add NewTabAdded() to listen in onLoc:
gBrowser.tabContainer.addEventListener("TabOpen", newTabAdded,
false);

But this result in the fact an URL will be submitted twice. Once in onLoc
and once in NewTabAdded. I am thinking of using an array to keep tracking
all URL open'ed. But I wonder if there is a more elegant way to do so.

--
Li Hong

Eric Jung

unread,
Dec 22, 2009, 10:52:46 AM12/22/09
to dev-ext...@lists.mozilla.org

What problem are you trying to solve? I don't understand.

Eric

Li Hong

unread,
Dec 23, 2009, 1:38:44 AM12/23/09
to dev-ext...@lists.mozilla.org
Hi list,

When I try to use document.getElementsByTagName('title') in onLocationChange
event, it returns null object. I guess that's because this onLoc event is
fired as soon as I enter an URL in in the address bar. Thus the html
document has been populated yet. Is my understanding correct?

Also curious to know if I can listen to a diff event within another event.
Say, to make sure my getElementsByTagName() will work, I may listen to
load() event inside onLocationChange()?


Thanks,

> --
> Li Hong
>
>
>


--
Li Hong

Eric Jung

unread,
Dec 25, 2009, 2:26:31 AM12/25/09
to dev-ext...@lists.mozilla.org
On Wed, Dec 23, 2009 at 1:38 AM, Li Hong <cef...@gmail.com> wrote:

> Hi list,
>
> When I try to use document.getElementsByTagName('title') in
> onLocationChange
> event, it returns null object. I guess that's because this onLoc event is
> fired as soon as I enter an URL in in the address bar. Thus the html
> document has been populated yet. Is my understanding correct?
>
>

I don't know, but you can ensure document.getElementsByTagName('title') is
called after window load and domcontentloaded with this:

https://developer.mozilla.org/en/Code_snippets/On_page_load#Attaching_a_script

Note the use of both load and DOMContentLoaded events.

Eric

0 new messages