BBjHtmlView::executeScript

Description

In BBj 16.0 and higher, this method executes the specified JavaScript in this BBjHtmlView control.

Syntax

Return Value

Method

Object

executeScript(string script)

Parameters

Variable

Description

script

JavaScript to be executed in this BBjHtmlView.

Return Value

In BBj 16.0, this method does not return a value.

In BBj 17.0 and higher, 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

None.

Example 1

Copy

BBjHtmlView::executeScript Example 1

rem ' BBjHtmlView::executeScript
bui = info(3,6)="5"
dwc = info(3,6)="6"
client = 0
if info(3,6)<>"5" and info(3,6)<>"6" then
   client = msgbox("BBjHtmlView Client",7+32+512,"BBjHtmlView","Swing","JavaFX","Chromium")
   switch client
      case 1; rem ' Swing
         print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=FALSE",ERR=*NEXT)
         print stbl("!OPTIONS","JAVAFX_HTMLVIEW=FALSE",ERR=*NEXT)
         break
      case 2; rem ' JavaFX
         print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=FALSE",ERR=*NEXT)
         print stbl("!OPTIONS","JAVAFX_HTMLVIEW=TRUE",ERR=*NEXT)
         break
      case 3; rem ' Chromium
         print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=TRUE",ERR=*NEXT)
         print stbl("!OPTIONS","JAVAFX_HTMLVIEW=TRUE",ERR=*NEXT)
         break
   swend
endif
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(50,50,300,300,"executeScript",$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")
if bui or dwc then
   script$ = "function testjs(parameter1) { alert(parameter1); }"
   htmlview!.injectScript(script$)
endif
executeScript! = window!.addButton(1,25,200,250,25,"executeScript")
executeScript!.setCallback(executeScript!.ON_BUTTON_PUSH,"executeScript")
js! = window!.addStaticText(100,25,250,250,25,"",$$)
print "getClientType: ",htmlview!.getClientType(err=*next)
print "getClientVersion: ",htmlview!.getClientVersion(err=*next)
process_events
eoj:
release
makehtml:
html$ = "<html><head></head>"
html$ = html$+"<body>"
html$ = html$+"<b>this is html</b>"
html$ = html$+"<script>"
html$ = html$+"function testjs(parameter1) { alert(parameter1); }"
html$ = html$+"</script>"
html$ = html$+"</body></html>"
return
executeScript:
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 bui or dwc then js$ = "style.backgroundColor = """+rgb$+""""
print js$
js!.setText(js$)
print "executeScript ",js$," returns ",htmlview!.executeScript(js$)
htmlview!.executeScript("testjs('"+js$+"')")
return
pageloaded:
print sysgui!.getLastEvent()
return

Example 2

Copy

BBjHtmlView::executeScript Example 2

rem ' BBjHtmlView::executeScript
client = 0
if info(3,6)<>"5" and info(3,6)<>"6" then
   client = msgbox("BBjHtmlView Client",7+32+512,"BBjHtmlView","Swing","JavaFX","Chromium")
   switch client
      case 1; rem ' Swing
         print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=FALSE",ERR=*NEXT)
         print stbl("!OPTIONS","JAVAFX_HTMLVIEW=FALSE",ERR=*NEXT)
         break
      case 2; rem ' JavaFX
         print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=FALSE",ERR=*NEXT)
         print stbl("!OPTIONS","JAVAFX_HTMLVIEW=TRUE",ERR=*NEXT)
         break
      case 3; rem ' Chromium
         print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=TRUE",ERR=*NEXT)
         print stbl("!OPTIONS","JAVAFX_HTMLVIEW=TRUE",ERR=*NEXT)
         break
   swend
endif
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(50,50,400,200,"BBjHtmlView",$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
html$ = "<html><head><style>p{margin:0;padding:0;}</style><title>BASIS</title></head>"
img$ = "http://www.basis.com/sites/basis.com/files/images/BusJGBetter.jpg"
html$ = html$ + "<body><img src="""+img$+""">"
url$ = "http://documentation.basis.com/BASISHelp/WebHelp/gridctrl2/bbjhtmlview.htm"
html$ = html$ + "<p>This is a <a href="""+url$+""">BBjHtmlView</a>."
html$ = html$ + "</body></html>"
htmlview! = window!.addHtmlView(101,25,25,350,150,html$)
htmlview!.setCallback(htmlview!.ON_PAGE_LOADED,"page")
htmlview!.setCallback(htmlview!.ON_HYPERLINK_ACTIVATE,"event")
process_events
eoj:
release
event:
return
page:
if info(3,6)="5" or info(3,6)="6" then body$ = "" else body$ = "document.body."
info$ = ""
js$ = body$ + "style.backgroundColor = ""#ffff00"""; gosub js
js$ = "Math.PI"; gosub js
js$ = "Math.sqrt(100)"; gosub js
js$ = "Math.sqrt(-1)"; gosub js
js$ = "document.hasFocus()"; gosub js
js$ = body$ + "style.backgroundColor"; gosub js
i = msgbox(info$)
return
js:
info$ = info$ + "executeScript: "+js$ + $0a$
js! = htmlview!.executeScript(js$)
if js! = null() then
   info$ = info$ + "result: null"
else
   info$ = info$ + "result: " + js!.getClass().getName()+" = "+js!.toString()
endif
info$ = info$ + $0a0a$
return

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

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