BBjHtmlView::injectScript

Description

In BBj 16.00 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

Parameter

Description

script

JavaScript to be injected into this BBjHtmlView.

top

A value specifying whether this script is to be injected into the top level window of the page (BBj 17.0 and higher).

Return Value

None.

Example

rem ' BBjHtmlView::injectScript

sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
title$ = "BBjHtmlView::injectScript"
window! = sysgui!.addWindow(50,50,300,300,title$,$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
gosub makehtml
htmlview! = window!.addHtmlView(101,25,25,250,150,html$)
htmlview!.setCallback(htmlview!.ON_PAGE_LOADED,"loaded")
htmlview!.setCallback(htmlview!.ON_SCRIPT_LOADED,"scriptloaded")
htmlview!.setCallback(htmlview!.ON_SCRIPT_FAILED,"scriptfailed")
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()
print "getClientVersion: ",htmlview!.getClientVersion()

bui = info(3,6)="5"
web = info(3,6)="6"

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 type=""text/javascript"">"
  html$ = html$+"function testjs(parameter1){alert(parameter1);}"
  html$ = html$+"</script>"
  html$ = html$+"</body></html>"
return

loaded:
  event! = sysgui!.getLastEvent()
  print event!.getEventName()
  script$ = "function testjs(parameter1){alert(parameter1);}"
  htmlview!.injectScript(script$,1)
  if bui then htmlview!.injectScript(script$,0)
return

scriptloaded:
  event! = sysgui!.getLastEvent()
  msg$ = date(0:"%Hz:%mz:%sz.%tz %p ")+event!.getEventName()
  msg$ = msg$ + " url="+str(event!.getUrl())
  msg$ = msg$ + ",text="+str(event!.getText())
  print msg$
  i = msgbox(msg$,0,event!.getEventName())
  gosub click; rem ' this works because we waited until the script was loaded
return

scriptfailed:
  event! = sysgui!.getLastEvent()
  msg$ = date(0:"%Hz:%mz:%sz.%tz %p ")+event!.getEventName()
  msg$ = msg$ + " url="+str(event!.getUrl())
  msg$ = msg$ + ",text="+str(event!.getText())
  print msg$
  i = msgbox(msg$,16,event!.getEventName())
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 web then js$ = "style.backgroundColor = """+rgb$+""""
  print js$
  js!.setText(js$)
  System.out.println("getScriptValue="+str(htmlview!.getScriptValue()))
  print "executeScript=",htmlview!.executeScript(js$)
  System.out.println("getScriptValue="+str(htmlview!.getScriptValue()))
  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.