wait for event

H

hollex2108

Hi,

I search for a method how my function detect an event while js is
carry out a loop.

I think it's not really important for a problem solving, but goodness
knows: I want to automate a web-application (GUI in html) from the
client-side. Therefor I use FireFox with xul.

I have several self defined js-objects. The object 'Main' control the
program flow. To control a dialog I use an object 'XYZDlg'. My object
'Browser' interact with a browser-control.

Now, for example, I want to extract data from a web-side (please see
what I basically write subsequent).

My problem is, that the function 'waitUntilPageIsLoaded' not work. If
I use a while-loop js never discover that the side is loaded. If I use
window.setTimeout/setIntervall instead of the loop, the function
'waitUntilPageIsLoaded' will be leaving before the side is loaded an
so the function 'getData' cause an error becaus the field with the
data exist not yet.

main.extractXYZData();

var Main = function() {
this.extractXYZData = function() {
xyzDlg.setSearchCriteria(value);
xyzDlg.search();
db.saveXYZData(XYZDlg.getData(););
}
}

var XYZDlg = function() {
this.setSearchCriteria= function(pValue) {
browser.setValueByID(IDSearchField, pValue);
}
this.search= function() {
browser.clickButton(IDSearchButton);
}
this.getData= function() {
return browser.getFieldValueByID(IDResultField);
}
}

var Browser= function() {
var PageIsLoaded=false;

waitUntilPageIsLoaded() = function() {
while (PageIsLoaded==false) {
//doEvents();
}
}

listObj.onStateChange = function(aProgress, aRequest, aFlag, aStatus)
{
save(CARRIAGE_RETURN + LINEFEED +'Browser.onStateChange()');
if (aFlag & listObj.wpl.STATE_START) {
PageIsLoaded=false;
// This fires when the load event is initiated
} else {
if (aFlag & listObj.wpl.STATE_STOP) {
if ( aFlag & listObj.wpl.STATE_IS_WINDOW ) {
// This fires when ALL load finish
}
if ( aFlag & listObj.wpl.STATE_IS_NETWORK ) {
// Fires when ALL load are REALLY
over,
PageIsLoaded=true;
}
}
}
return 0;
}
myBrowserControl.addProgressListener( listObj,

Components.interfaces.nsIWebProgress.NOTIFY_STATE_WINDOW );

this.setValueByID= function(pID, pValue) {
browser.getElementById(pID).value = pValue;
}
this.clickButton= function(pID) {
browser.getElementById(pID).click();
waitUntilPageIsLoaded();
}
this.getFieldValueByID= function(pID) {
return browser.getElementById(pID).value;
}
}
 
V

VK

My problem is, that the function 'waitUntilPageIsLoaded' not work. If
I use a while-loop js never discover that the side is loaded. If I use
window.setTimeout/setIntervall instead of the loop, the function
'waitUntilPageIsLoaded' will be leaving before the side is loaded an
so the function 'getData' cause an error becaus the field with the
data exist not yet.

Does it help?
http://developer.mozilla.org/en/docs/Code_snippets:On_page_load

Also you may ask at mozilla.dev.tech.xul
 
H

hollex2108

Hi VK,

no, unfortunately it doesn't help.

As you can see in my example-code, I already have a event-listener-
function (listObj.onStateChange). It works if I don't use a while-
loop(waitUntilPageIsLoaded). But if I use a while-loop, I think the js-
thread only can loop. I think it can't listen for an event at the same
time. So the loop never ends.
What I need is something like a DoEvent-function as in VisualBasic.

Regards hollex
 
H

hollex2108

Hi VK,

no, unfortunately it doesn't help.

As you can see in my example-code, I already have a event-listener-
function (listObj.onStateChange). It works if I don't use a while-
loop(waitUntilPageIsLoaded). But if I use a while-loop, I think the js-
thread only can loop. I think it can't listen for an event at the same
time. So the loop never ends.
What I need is something like a DoEvent-function as in VisualBasic.

Regards hollex
 
V

VK

Hi VK,

no, unfortunately it doesn't help.

As you can see in my example-code, I already have a event-listener-
function (listObj.onStateChange). It works if I don't use a while-
loop(waitUntilPageIsLoaded). But if I use a while-loop, I think the js-
thread only can loop. I think it can't listen for an event at the same
time. So the loop never ends.
What I need is something like a DoEvent-function as in VisualBasic.

AFAIK there is not anything like DoEvent (VB) or SIG (semaphore-driven
execution like say Perl) in Javascript: it is a single-threaded
environment.

You have to instruct XUL to listen for load event from the page and
then propagate it to your C consumer - and then just relax (stop the
execution) and wait for onevent calls.

mozilla.dev.tech.xul may have better ideas.
 
H

hollex2108

Thanks,

by mozilla.dev.tech.xul I have searched for help, but not found.

I've suspect that there is not other way to do it as to use an event-
handler.
But now, I don't now how I can implement it in my object-structure.
Till now I have a sequence witch will be started by clicking a button,
but next, after the user has click the button, the sequence will
start, then end, then, after the browser fire an event, step into the
sequence....

I don't know how I can implement it in my object-structure. Any
recommendations?
 
H

hollex2108

objMain objDialg objBrowser
objDatabase
-------- -------- ----------
-----------
------------------------ eventHandler_onLoad
| |
openDataDlg <- |
| -----------------------> clickButton |
| |
| |
getData ----> searchData -------> setFieldValue |
| | | |-------------> clickButton |
| | |<----------------------------------|
| |
| |---- getData ----------> getFieldValue
|
saveData ----------------------------------------------->
openDB
|->
insertIntoDB
 
T

Thomas 'PointedEars' Lahn

objMain objDialg objBrowser
objDatabase
-------- -------- ----------
-----------
------------------------ eventHandler_onLoad
| |
openDataDlg <- |
| -----------------------> clickButton |
| |
| |
getData ----> searchData -------> setFieldValue |
| | | |-------------> clickButton |
| | |<----------------------------------|
| |
| |---- getData ----------> getFieldValue
|
saveData ----------------------------------------------->
openDB
|->
insertIntoDB

I suggest you use a fixed-width font and don't exceed 72 characters per
line for posting ASCII art. Or you may post the URI of your text file
instead. Not using Google Groups for posting also helps.


PointedEars
 
V

VK

objMain objDialg objBrowser
objDatabase
-------- -------- ----------
-----------
------------------------ eventHandler_onLoad
| |
openDataDlg <- |
| -----------------------> clickButton |
| |
| |
getData ----> searchData -------> setFieldValue |
| | | |-------------> clickButton |
| | |<----------------------------------|
| |
| |---- getData ----------> getFieldValue
|
saveData ----------------------------------------------->
openDB
|->
insertIntoDB

I have to admit that C <--> XUL <--> Gecko API <--> JavaScript
intercommunications are out of any appropriate competence of mine.

I can only suggest again to ask for help at Mozilla forums, maybe
cross-post at mozilla.dev.tech.javascript, mozilla.dev.tech.js-
engine, mozilla.dev.tech.xul with Followup-To set to
mozilla.dev.tech.xul and see if any valuable answers back. These NGs
are not highly active but I know that they are regularly read by
people making all these things (lesser C itself :) so if anyone knows
a way then your best bet to find it is in there.
 
H

hollex2108

Hello VK,

thank you for trying to help. I will do what you suggest.
I just get a tip at mozilla.dev.tech.xul, witch I still must read.

Thanks
Hollex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top