BUI logoBBjWebManager::injectScriptUrl

Description

In BBj 22.03 and higher, this method injects the specified external JavaScript URL into the web page. External JavaScript is injected asynchronously; success or failure is reported with BBjScriptLoadedEvent or BBjScriptFailedEvent.

Note:

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

Syntax

Return Value Method

void

injectScriptUrl(string url)

void injectScriptUrl(string url, boolean top)
void injectScriptUrl(string url, boolean top, String attributes)
void injectScriptUrl(string url, boolean top, HashMap attributes)

Parameters

Variable

Description
url A JavaScript URL 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::injectScriptUrl

url$ = "https://www.poweredbybbj.com/files/scripts/hello.js"
top = 1
attributes$ = ""

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

title$ = "BBjWebManager::injectScriptUrl"
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,"URL:",$8000$)
url! = window!.addEditBox(102,100,25,475,25,url$,$$)

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$,$$)

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

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

browser! = bbjapi().getWebManager(err=oops)
browser!.setCallback(browser!.ON_SCRIPT_LOADED,"loaded")
browser!.setCallback(browser!.ON_SCRIPT_FAILED,"failed")

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()
    url!.setSize(width-125,25)
    top!.setSize(width-125,25)
    attributes!.setSize(width-125,25)
    injectScriptUrl!.setSize(width-125,25)
return

injectScriptUrl:
    url$ = url!.getText()
    top = top!.isSelected()
    attributes$ = attributes!.getText()
    browser!.injectScriptUrl(url$, top, attributes$)
return

loaded:
    event! = sysgui!.getLastEvent()
    msg$ = date(0:"%Hz:%mz:%sz.%tz %p ")+event!.getEventName()+" url="+str(event!.getUrl())
    i = msgbox(msg$)
return

failed:
    event! = sysgui!.getLastEvent()
    msg$ = date(0:"%Hz:%mz:%sz.%tz %p ")+event!.getEventName()+" url="+str(event!.getUrl())
    i = msgbox(msg$)
return

executeScript:
    wnd$ = ""
    if top!.isSelected() then 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.