Contents - Index


RunAnonymousFunction

 

Type: Method

Parameters: Integer Id Variant Params String Script 

Returns: Integer Error

 

 

Gives you the ability to run an anonymous javascript function. 

As all functionality via javascript is run in an asynchronous way, you can not get any results from the javascript function directly.

You can proces the return values in OnRunAnonymousFunction event that is triggered after the function completes.

By passing in an function Id you can track which function completed in OnRunAnonymousFunction event.

You can pass your parameters directly to the anonymous function by using a  variant array for Params.

 

You need to connect your document object to the current WebView control via CurrentBrowser

 

Example in DataFlex:

 

Define CFun_QueryCurrencyRate for 6

Define CFun_RateReceived      for 7

 

  Procedure QueryRatings

    String  sScript

    Integer iErr

    Number  nAmount

    String  sCurFrom

    String  sCurTo

    Variant[] Params

    

    Move "" To sScript

    Append sScript "(amount,curFrom,curTo) => {" CS_CRLF

    Append sScript "  displayGraph(curFrom,curTo);" CS_CRLF

    Append sScript "  let obj = document.getElementById('currencyRate');" CS_CRLF

    Append sScript "  if (obj !== undefined) {" CS_CRLF

    Append sScript "    obj.innerText = '-1'" CS_CRLF  // -1 is initialized.. 

    Append sScript "  }"

    Append sScript "  queryRates(amount,curFrom,curTo);" CS_CRLF

    Append sScript "}" CS_CRLF

    Send ConnectBrowser to oDocument

    Get Value of oAmountForm to nAmount

    Get Value of oFromCombo  to sCurFrom

    Get Value of oToCombo    to sCurTo

    Move nAmount  To Params[0]

    Move sCurFrom To Params[1]

    Move sCurTo   To Params[2]

    Get ComRunAnonymousFunction of oDocument CFun_QueryCurrencyRate Params sScript to iErr

  End_Procedure