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

waiting for somebody's page to load

27 views
Skip to first unread message

Sergei Riaguzov

unread,
Jul 26, 2008, 9:09:11 AM7/26/08
to
Hi.

How can I wait for a page to load in XUL application?

I have two windows, pressing a button in one of them opens some page
in another window.

anotherWindow.location.href = "http://somewhere/something";

I've searched through google and found several ways to wait until this
page is loaded:

anotherWindow.onload = ...
anotherWindow.addActionListener('load', ...)
anotherWindow.document.addActionListener('load', ...)
anotherWindow.document.getElementById('appcontent').addActionListener('DOMContentLoaded'), ...)

but non of those worked. I think it is because when I do:

anotherWindow.location.href = ...

the page is loaded into anotherWindow which discards all my javascript
action listeners.

How can this be solved? Maybe it is possible to load a page in a
"blocking way", something like:

anotherWindow.loadBlocking('http://somewhere/something')

?

The example xullap is here:

http://brylant.iit.pwr.wroc.pl/~srahuzau/xulapp.zip

After unpacking:

xulrunner application.ini

or if it is Firefox3

firefox -app application.ini

After pressing Load http://www.google.com is loaded into another
window. How can I wait until it is fully loaded or at least check
whether it is fully loaded?

Sergey Yanovich

unread,
Jul 26, 2008, 9:53:46 AM7/26/08
to
Sergei Riaguzov wrote:
> How can I wait for a page to load in XUL application?

I am using nsIWebProgress interface to wait for loading.

Implementation may look like this:

const listener = {
/* nsIWebProgressListener implementaion */
QueryInterface: function(iid){
/* provide nsIWebProgressListener interface */
},

onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
/* check for (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) */
};

anotherWindow.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIWebProgress)
.addProgressListener(listener, Ci.nsIWebProgress.NOTIFY_STATE_WINDOW);

Sergei Riaguzov

unread,
Jul 26, 2008, 12:08:59 PM7/26/08
to
On Jul 26, 3:53 pm, Sergey Yanovich <ynv...@gmail.com> wrote:

> > How can I wait for a page to load in XUL application?
> I am using nsIWebProgress interface to wait for loading.
> Implementation may look like this:

[skip]
Thanks.. Can all this stuff be done in Javascript or those interfaces
are not available there?

Sergei Riaguzov

unread,
Jul 26, 2008, 12:19:50 PM7/26/08
to
On Jul 26, 6:08 pm, Sergei Riaguzov <riagu...@gmail.com> wrote:

> > > How can I wait for a page to load in XUL application?
> > I am using nsIWebProgress interface to wait for loading.
> > Implementation may look like this:
>
> [skip]
> Thanks.. Can all this stuff be done in Javascript or those interfaces
> are not available there?

Gee.. This IS Javascript, I'm so stupid. ;)

Sergei Riaguzov

unread,
Jul 26, 2008, 3:14:58 PM7/26/08
to
On Jul 26, 3:53 pm, Sergey Yanovich <ynv...@gmail.com> wrote:

> anotherWindow.getInterface(Ci.nsIWebNavigation)
>    .QueryInterface(Ci.nsIWebProgress)
>    .addProgressListener(listener, Ci.nsIWebProgress.NOTIFY_STATE_WINDOW);
OK, it worked.. Although it's not that simple. I will post my working
solution here if anybody will search for something similar. The code
you provided doesn't work if anotherWindow is just a XUL <window>. I
had to do something like that:

=== Cut ===
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="anotherWindow" title="AnotherWindow" width="800"
height="600"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul">

<browser id="browser-content" type="content-primary"
src="about:blank" flex="1"/>
</window>
=== Cut ===

Now, having this window with a browser embedded I can do:

const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
const nsIWebProgress = Components.interfaces.nsIWebProgress;
const nsIWebProgressListener =
Components.interfaces.nsIWebProgressListener;
const nsISupportsWeakReference =
Components.interfaces.nsISupportsWeakReference;

var myBrowser = anotherWindow.document.getElementById("browser-
content");
var wp = myBrowser.webNavigation.QueryInterface(nsIWebProgress);
wp.addProgressListener(listener, nsIWebProgress.NOTIFY_STATE_WINDOW);

// Now when I loadURI like:

myBrowser.webNavigation.loadURI("http://www.google.com",
nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);

Assuming my listener is:

var listener = {
QueryInterface: function (iid) {
if (iid.equals(nsIWebProgressListener) ||
iid.equals(nsISupportsWeakReference))
return this;
throw Components.results.NS_NOINTERFACE;
},
onStateChange: function (webProgress, request, stateFlags, status) {
if (stateFlags & nsIWebProgressListener.STATE_STOP) {
alert('OK');
}
}
};

I do achieve what I need: alert is shown.

0 new messages