等待事件 [英] wait for event

查看:54
本文介绍了等待事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我搜索一个方法,我的函数检测一个事件,而js是

执行一个循环。


我认为这对于解决问题并不重要,但是善良

知道:我想从

客户端。因此我使用带有xul的FireFox。


我有几个自定义的js对象。对象''Main''控制

程序流程。为了控制对话框,我使用了一个对象''XYZDlg''。我的目标

''浏览器''与浏览器控件交互。


现在,例如,我想从网络侧提取数据(请看

我后来基本上写的是什么。


我的问题是,函数''waitUntilPageIsLoaded''不起作用。如果

我使用while循环js永远不会发现侧面已加载。如果我使用

window.setTimeout / setIntervall而不是循环,那么函数

''waitUntilPageIsLoaded''将在加载一边之前离开

所以函数''getData''会导致错误,因为

数据的字段尚不存在。


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(){

返回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(b) aFlag& listObj.wpl.STATE_START){

PageIsLoaded = false;

//启动加载事件时触发

}其他{

if(aFlag& listObj.wpl.STATE_STOP){

if(aFlag& listObj.wpl.STATE_IS_WINDOW){

//这会引发火灾当所有载荷完成时

}

if(aFlag& listObj.wpl.STATE_IS_NETWORK){

//当所有载荷真正

结束,

PageIsLoaded = true;

}

}

}

返回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){

返回browser.getElementById(pID).value;

}

}

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;
}
}

推荐答案

5月20日下午5:34,hollex2 ... @ yahoo.de写道:
On May 20, 5:34 pm, hollex2...@yahoo.de wrote:

我的问题是,函数''waitUntilPageIsLoaded''不行。如果

我使用while循环js永远不会发现侧面已加载。如果我使用

window.setTimeout / setIntervall而不是循环,那么函数

''waitUntilPageIsLoaded''将在加载一边之前离开

因此函数''getData''导致错误,因为

数据的字段尚未存在。
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.



它有帮助吗?
http://developer.mozilla.org/en/docs...s:On_page_load


您也可以在mozilla询问。 dev.tech.xul

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

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


嗨VK,


不,不幸的是它无济于事。


正如你在我的示例代码中看到的,我已经有了一个事件监听器 -

函数(listObj.onStateChange)。如果我不使用while-

循环(waitUntilPageIsLoaded),它就可以工作。但是如果我使用while循环,我认为js-

线程只能循环。我认为它不能在同一时间听取一个事件。所以循环永远不会结束。

我需要的是类似于VisualBasic中的DoEvent函数。


关于hollex
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


嗨VK,


不,不幸的是它没有帮助。


正如你在我看到的那样示例代码,我已经有一个事件监听器 -

函数(listObj.onStateChange)。如果我不使用while-

循环(waitUntilPageIsLoaded),它就可以工作。但是如果我使用while循环,我认为js-

线程只能循环。我认为它不能在同一时间听取一个事件。所以循环永远不会结束。

我需要的是类似于VisualBasic中的DoEvent函数。


关于hollex
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


这篇关于等待事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆