wait for event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hollex2108@yahoo.de

    wait for event

    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 'waitUntilPageI sLoaded' not work. If
    I use a while-loop js never discover that the side is loaded. If I use
    window.setTimeo ut/setIntervall instead of the loop, the function
    'waitUntilPageI sLoaded' 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.extractXYZ Data();

    var Main = function() {
    this.extractXYZ Data = function() {
    xyzDlg.setSearc hCriteria(value );
    xyzDlg.search() ;
    db.saveXYZData( XYZDlg.getData( ););
    }
    }

    var XYZDlg = function() {
    this.setSearchC riteria= function(pValue ) {
    browser.setValu eByID(IDSearchF ield, pValue);
    }
    this.search= function() {
    browser.clickBu tton(IDSearchBu tton);
    }
    this.getData= function() {
    return browser.getFiel dValueByID(IDRe sultField);
    }
    }

    var Browser= function() {
    var PageIsLoaded=fa lse;

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

    listObj.onState Change = function(aProgr ess, aRequest, aFlag, aStatus)
    {
    save(CARRIAGE_R ETURN + LINEFEED +'Browser.onSta teChange()');
    if (aFlag & listObj.wpl.STA TE_START) {
    PageIsLoaded=fa lse;
    // This fires when the load event is initiated
    } else {
    if (aFlag & listObj.wpl.STA TE_STOP) {
    if ( aFlag & listObj.wpl.STA TE_IS_WINDOW ) {
    // This fires when ALL load finish
    }
    if ( aFlag & listObj.wpl.STA TE_IS_NETWORK ) {
    // Fires when ALL load are REALLY
    over,
    PageIsLoaded=tr ue;
    }
    }
    }
    return 0;
    }
    myBrowserContro l.addProgressLi stener( listObj,

    Components.inte rfaces.nsIWebPr ogress.NOTIFY_S TATE_WINDOW );

    this.setValueBy ID= function(pID, pValue) {
    browser.getElem entById(pID).va lue = pValue;
    }
    this.clickButto n= function(pID) {
    browser.getElem entById(pID).cl ick();
    waitUntilPageIs Loaded();
    }
    this.getFieldVa lueByID= function(pID) {
    return browser.getElem entById(pID).va lue;
    }
    }
  • VK

    #2
    Re: wait for event

    On May 20, 5:34 pm, hollex2...@yaho o.de wrote:
    My problem is, that the function 'waitUntilPageI sLoaded' not work. If
    I use a while-loop js never discover that the side is loaded. If I use
    window.setTimeo ut/setIntervall instead of the loop, the function
    'waitUntilPageI sLoaded' 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?
    The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.


    Also you may ask at mozilla.dev.tec h.xul

    Comment

    • hollex2108@yahoo.de

      #3
      Re: wait for event

      Hi VK,

      no, unfortunately it doesn't help.

      As you can see in my example-code, I already have a event-listener-
      function (listObj.onStat eChange). It works if I don't use a while-
      loop(waitUntilP ageIsLoaded). 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

      Comment

      • hollex2108@yahoo.de

        #4
        Re: wait for event

        Hi VK,

        no, unfortunately it doesn't help.

        As you can see in my example-code, I already have a event-listener-
        function (listObj.onStat eChange). It works if I don't use a while-
        loop(waitUntilP ageIsLoaded). 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

        Comment

        • VK

          #5
          Re: wait for event

          On May 21, 11:25 am, hollex2...@yaho o.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.onStat eChange). It works if I don't use a while-
          loop(waitUntilP ageIsLoaded). 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.tec h.xul may have better ideas.

          Comment

          • hollex2108@yahoo.de

            #6
            Re: wait for event

            Thanks,

            by mozilla.dev.tec h.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 ?

            Comment

            • hollex2108@yahoo.de

              #7
              Re: wait for event

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

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: wait for event

                hollex2108@yaho o.de wrote:
                objMain objDialg objBrowser
                objDatabase
                -------- -------- ----------
                -----------
                ------------------------ eventHandler_on Load
                | |
                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 bugRiddenCrashP ronePieceOfJunk = (
                navigator.userA gent.indexOf('M SIE 5') != -1
                && navigator.userA gent.indexOf('M ac') != -1
                ) // Plone, register_functi on.js:16

                Comment

                • hollex2108@yahoo.de

                  #9
                  Re: wait for event

                  Thanks for suggestion.

                  Comment

                  • VK

                    #10
                    Re: wait for event

                    On May 21, 4:29 pm, hollex2...@yaho o.de wrote:
                    objMain objDialg objBrowser
                    objDatabase
                    -------- -------- ----------
                    -----------
                    ------------------------ eventHandler_on Load
                    | |
                    openDataDlg <- |
                    | ----------------------- clickButton |
                    | |
                    | |
                    getData ----searchData -------setFieldValue |
                    | | | |-------------clickButton |
                    | | |<----------------------------------|
                    | |
                    | |---- getData ----------getFieldValue
                    |
                    saveData ----------------------------------------------->
                    openDB
                    |->
                    insertIntoDB
                    I have to admit that C <--XUL <--Gecko API <--JavaScript
                    intercommunicat ions 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.tec h.javascript, mozilla.dev.tec h.js-
                    engine, mozilla.dev.tec h.xul with Followup-To set to
                    mozilla.dev.tec h.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.

                    Comment

                    • hollex2108@yahoo.de

                      #11
                      Re: wait for event

                      Hello VK,

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

                      Thanks
                      Hollex

                      Comment

                      Working...