BBjSysGui::executeScript

Description

In BBj 21.10 and higher, this method executes the specified JavaScript in this web page (see Remarks).

Syntax

Return Value Method
Object executeScript(string script)

Parameters

Variable Description
script JavaScript to be executed in this web page.

Return Value

This method returns the execution result, converted from JavaScript to Java. If the return value is a JavaScript type that can't be represented as a Java type, a simple String representation is returned.

Remarks

In BBj 22.02 and higher, a subset of this functionality is available in the GUI client. Because the client isn't a web page, user-facing components, including Window, Document, and functions like alert, aren't available.

BUI logoDWC logoExample

rem ' BBjSysGui::executeScript Example 1: BUI and DWC

rem ' BBjSysGui::executeScript
bui = info(3,6)="5"
dwc = info(3,6)="6"
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(50,50,300,200,"executeScript",$00090003$)
window!.setCallback(window!.ON_CLOSE,"eoj")
executeScript! = window!.addButton(1,25,25,250,25,"executeScript")
executeScript!.setCallback(executeScript!.ON_BUTTON_PUSH,"executeScript")
js! = window!.addStaticText(101,25,75,250,100,"",$$)
script$ = "function testjs(parameter1){alert('testjs: '+parameter1);}"
sysgui!.injectScript(script$,1)
doc$ = iff(bui,"$doc","document")
wnd$ = iff(bui,"$wnd","window")
process_events

eoj:
release
return

executeScript:
    r = rnd(255)
    g = rnd(255)
    b = rnd(255)
    rgb$ = "#"+hta(chr(r))+hta(chr(g))+hta(chr(b))
    js$ = doc$+".body.style.backgroundColor = """+rgb$+""""
    print js$
    js!.setText(js$)
    print sysgui!.executeScript(js$)
    print sysgui!.executeScript(wnd$+".testjs('"+js$+"')")
return

Example 2 (All Clients)

rem ' BBjSysGui::executeScript

sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(25,25,500,175,"toISOString",$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.addStaticText(101,25,28,120,25,"Date String:",$8000$)
text$ = "December 25, " + date(0:"%Yl")
text! = window!.addEditBox(102,150,25,325,25,text$,$$)
window!.addStaticText(103,25,78,120,25,"ISO String:",$8000$)
result! = window!.addEditBox(104,150,75,325,25,"",$0200$)
result!.setBackColor(BBjColor.WHITE)

rem ' https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
js$ = "function toISOString(date){try{return new Date(date).toISOString()}catch(e){return new String(e)}}"
sysgui!.injectScript(js$)
toISOString! = window!.addButton(1,150,125,150,25,"toISOString",$$)
toISOString!.setCallback(toISOString!.ON_BUTTON_PUSH,"toISOString")
close! = window!.addButton(2,325,125,150,25,"Close",$$)
close!.setCallback(close!.ON_BUTTON_PUSH,"eoj")
process_events

eoj:
release

toISOString:
    text$ = text!.getText()
    script$ = "toISOString('"+text$+"')"
    ISOString! = sysgui!.executeScript(script$)
    result!.setText(str(ISOString!))
return

ClosedVersion History

  • BBj 21.10: BBjSysGui::executeScript introduced.
  • BBj 22.02: Added a subset of this functionality in the GUI client.

See Also

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

BBjAPI

BBjSysGui

BBjSysGui::injectScript