By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

wait for event

P: n/a
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;
}
}
Jun 27 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
VK
On May 20, 5:34 pm, hollex2...@yahoo.de wrote:
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...s:On_page_load

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

Jun 27 '08 #2

P: n/a
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
Jun 27 '08 #3

P: n/a
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
Jun 27 '08 #4

P: n/a
VK
On May 21, 11:25 am, hollex2...@yahoo.de wrote:
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.
Jun 27 '08 #5

P: n/a
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?
Jun 27 '08 #6

P: n/a
objMain objDialg objBrowser
objDatabase
-------- -------- ----------
-----------
------------------------ eventHandler_onLoad
| |
openDataDlg <- |
| ----------------------- clickButton |
| |
| |
getData ----searchData -------setFieldValue |
| | | |-------------clickButton |
| | |<----------------------------------|
| |
| |---- getData ----------getFieldValue
|
saveData ----------------------------------------------->
openDB
|->
insertIntoDB
Jun 27 '08 #7

P: n/a
ho********@yahoo.de wrote:
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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 27 '08 #8

P: n/a
Thanks for suggestion.

Jun 27 '08 #9

P: n/a
VK
On May 21, 4:29 pm, hollex2...@yahoo.de wrote:
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.
Jun 27 '08 #10

P: n/a
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
Jun 27 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.