BUI logoDWC logoBBjWebManager::injectScript

Description

In BBj 22.03 and higher, this method injects the specified JavaScript into the web page.

Note:

In BBj 22.03 and higher, BBjWebManager is an alias for BBjBuiManager.

Syntax

Return Value Method

void

injectScript(String script)
void injectScript(String script, boolean top)
void injectScript(String script, boolean top, String attributes)

void

injectScript(String script, boolean top, HashMap attributes)

Parameters

Parameter Description

script

JavaScript to be injected into this web page as a script element.

top A boolean value specifying whether this script is to be injected into the top level window of the page.
attributes A set of attributes to be added to the script element. Attributes can be specified either as a string in the format "attr=value,attr=value" or as a HashMap containing key/value pairs.

Return Value

None.

Example

rem ' BBjWebManager::injectScript

script$ = "function hello() { alert('Hello from JavaScript') }"
top = 1
attributes$ = ""

sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()

title$ = "BBjWebManager::injectScript"
window! = sysgui!.addWindow(25,25,600,275,title$,$00090083$)
window!.setCallback(window!.ON_RESIZE,"resize")
window!.setCallback(window!.ON_CLOSE,"eoj")

window!.addStaticText(101,5,25,90,25,"Script:",$8000$)
script! = window!.addEditBox(102,100,25,475,25,script$,$$)

top! = window!.addCheckBox(103,100,75,475,25,"Top",$$)
top!.setSelected(top)

window!.addStaticText(104,5,125,90,25,"Attributes:",$8000$)
attributes! = window!.addEditBox(105,100,125,475,25,attributes$,$$)

injectScript! = window!.addButton(1,100,175,475,25,"injectScript",$$)
injectScript!.setCallback(injectScript!.ON_BUTTON_PUSH,"injectScript")

executeScript! = window!.addButton(2,100,225,475,25,"executeScript",$$)
executeScript!.setCallback(executeScript!.ON_BUTTON_PUSH,"executeScript")

browser! = bbjapi().getWebManager(err=oops)

process_events

oops:
i = msgbox("This functionality is only supported in browser environments.")

eoj:
release

resize:
    event! = sysgui!.getLastEvent()
    width = event!.getWidth()
    height = event!.getHeight()
    script!.setSize(width-125,25)
    top!.setSize(width-125,25)
    attributes!.setSize(width-125,25)
    injectScript!.setSize(width-125,25)
return

injectScript:
    script$ = script!.getText()
    top = top!.isSelected()
    attributes$ = attributes!.getText()
    browser!.injectScript(script$, top, attributes$)
return

executeScript:
    wnd$ = iff(info(3,6)="5","$wnd.","window.")
    sysgui!.executeScript(wnd$+"hello();")
return

See Also

BBjAPI

BBjSysGui

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