BBjExecuteScriptEvent::getResult

Description

In BBj 19.10 and higher, this method returns the result of BBjHtmlView::executeAsyncScript or (in BBj 22.14 and higher) BBjBuiManager::executeAsyncScript.

Syntax

Return Value

Method

Object

getResult()

Parameters

None.

Return Value

Returns the result of BBjHtmlView::executeAsyncScript or (in BBj 22.14 and higher) BBjBuiManager::executeAsyncScript.

Remarks

When returning values from JavaScript to Java, the following conversions are applied:

JavaScript numbers are converted to java.lang.Integer, java.lang.Long, or java.lang.Double.

JavaScript strings are converted to java.lang.String.

JavaScript booleans are converted to java.lang.Boolean.

JavaScript null and undefined are converted to null.

All other types are converted to a string representation.

Example

rem ' BBjExecuteScriptEvent::getResult

sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(50,50,300,400,"BBjExecuteScriptEvent::getResult",$00090003$)
window!.setCallback(window!.ON_CLOSE,"eoj")
gosub makehtml
htmlview! = window!.addHtmlView(101,25,25,250,150,html$)
htmlview!.setCallback(htmlview!.ON_PAGE_LOADED,"pageloaded")
htmlview!.injectScript("function doAlert() { console.log(alert('Alert dialog')); }",1)
htmlview!.injectScript("function doConfirm() { console.log(confirm('Confirm dialog')); }",1)
htmlview!.injectScript("function doPrompt() { console.log(prompt('Prompt dialog')); }",1)
print "getClientType: ",htmlview!.getClientType()
print "getClientVersion: ",htmlview!.getClientVersion()
alert! = window!.addButton(102,25,200,250,25,"alert",$$)
alert!.setCallback(alert!.ON_BUTTON_PUSH,"alert")
confirm! = window!.addButton(103,25,250,250,25,"confirm",$$)
confirm!.setCallback(alert!.ON_BUTTON_PUSH,"confirm")
prompt! = window!.addButton(104,25,300,250,25,"prompt",$$)
prompt!.setCallback(prompt!.ON_BUTTON_PUSH,"prompt")
backgroundColor! = window!.addButton(105,25,350,250,25,"backgroundColor",$$)
backgroundColor!.setCallback(backgroundColor!.ON_BUTTON_PUSH,"backgroundColor")
web = info(3,6)="5" or info(3,6)="6"

process_events

eoj:
  release

makehtml:
  html$ = ""
  html$ = html$ + "<!DOCTYPE html> <html> <body>"
  html$ = html$ + "<br><button onclick='doAlert()'>Alert</button>"
  html$ = html$ + "<br><button onclick='doConfirm()'>Confirm</button>"
  html$ = html$ + "<br><button onclick='doPrompt()'>Prompt</button>"
  html$ = html$ + "<script>"
  html$ = html$ + "function doAlert() { console.log(alert('Alert dialog')); }"
  html$ = html$ + "function doConfirm() { console.log(confirm('Confirm dialog')); }"
  html$ = html$ + "function doPrompt() { console.log(prompt('Prompt dialog')); }"
  html$ = html$ + "</script>"
  html$ = html$ + "</body> </html>"
return

pageloaded:
  htmlview!.setCallback(htmlview!.ON_EXECUTE_SCRIPT,"executeScript")
  print sysgui!.getLastEvent().getEventName()
return

alert:
  js$ = "alert('alert')"
  gosub executeAsyncScript
return

confirm:
  js$ = "confirm('confirm')"
  gosub executeAsyncScript
return

prompt:
  js$ = "prompt('prompt')"
  gosub executeAsyncScript
return
executeScript:
  event! = sysgui!.getLastEvent()
  result! = event!.getResult()
  msg$ = event!.getEventName()+" "+date(0:"%Hz:%mz:%sz.%tz %p")+$0a$
  msg$ = msg$ + event!.getScript()+": "
  if (result! = null()) then
    msg$ = msg$ + "null"
  else
    msg$ = msg$ + result!.getClass().getName() + " = " + result!.toString()
  endif
  print msg$
  i = msgbox(msg$)
return

backgroundColor:
  r = rnd(255)
  g = rnd(255)
  b = rnd(255)
  rgb$ = "#"+hta(chr(r))+hta(chr(g))+hta(chr(b))
  js$ = "document.body.style.backgroundColor = """+rgb$+""""
  if web then js$ = "style.backgroundColor = """+rgb$+""""
  gosub executeAsyncScript
return

executeAsyncScript:
  htmlview!.executeAsyncScript(js$)
  print "executeAsyncScript ",date(0:"%Hz:%mz:%sz.%tz %p")," ",js$
return

See Also

BBjAPI

BBj Object Syntax

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.