BBjHtmlView::injectScript

Description

In BBj 16.0 and higher, this method injects the specified JavaScript into this BBjHtmlView control, making it available for subsequent use by BBjHtmlView::executeScript.

Syntax

Return Value

Method

void

injectScript(string script)

void

injectScript(string script, boolean top)

Parameters

Return Value

Method

script

JavaScript to be injected into this BBjHtmlView.

top

In BBj 17 and higher, a value specifying whether this script is to be injected into the top level window of the page.

Return Value

None.

Remarks

This is only required in BUI, as shown in the example code.

Example

rem ' BBjHtmlView::injectScript
bui = info(3,6)="5"
client = 0
if info(3,6)<>"5" 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,"loaded")
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$+"<input type='button' onclick='testjs(""testing"")' value='Click Me!' style='margin:15px;'>"
    html$ = html$+"<script>"
    html$ = html$+"function testjs(parameter1) { alert(parameter1); }"
    html$ = html$+"</script>"
html$ = html$+"</body></html>"
return
loaded:
print sysgui!.getLastEvent()
script$ = "function testjs(parameter1){alert(parameter1);}"
htmlview!.injectScript(script$)
rem htmlview!.injectScript(script$,0)
rem htmlview!.injectScript(script$,1)
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 then js$ = "style.backgroundColor = """+rgb$+""""
print js$
js!.setText(js$)
print htmlview!.executeScript(js$)
print htmlview!.executeScript("testjs('"+js$+"')")
return

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

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



______________________________________________________________________________________

Copyright BASIS International Ltd. BBj®, Visual PRO/5®, PRO/5®, and BBx® are registered trademarks.