BUI logoDWC logoBBjWebManager::injectLinkUrl

Description

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

Note:

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

Syntax

Return Value Method
void injectLinkUrl(String url)
void injectLinkUrl(String url, boolean top)
void injectLinkUrl(String url, boolean top, String attributes)
void injectLinkUrl(String url, boolean top, HashMap attributes)

Parameters

Parameter Description
url A link URL to be injected into this web page as a link element.
top

Specifies which element the link URL will be injected into. By default, the link URL is injected into the head element.

true (1) = Injects the link URL into the head element.

false (0) = Injects the link URL into the body element.

attributes A set of attributes to be added to the link 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 1

rem ' BBjWebManager::injectLinkUrl

url$ = "https://fonts.googleapis.com/css2?family=Bungee+Spice&display=swap"
top = 1
attributes$ = "rel=stylesheet"

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

title$ = "BBjWebManager::injectLinkUrl"
window! = sysgui!.addWindow(25,25,600,250,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$,$$)

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

status! = window!.addStatusBar(99)

web! = bbjapi().getWebManager(err=oops)
web!.setCallback(web!.ON_LINK_LOADED,"loaded")
web!.setCallback(web!.ON_LINK_FAILED,"failed")

process_events

oops:
i = msgbox("This functionality is only supported in web 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)
  injectLinkUrl!.setSize(width-125,25)
return

injectLinkUrl:
  url$ = url!.getText()
  top = top!.isSelected()
  attributes$ = attributes!.getText()
  web!.injectLinkUrl(url$, top, attributes$)
return

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

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

Example 2

rem ' BBjFontChooser

if info(3,6)<>"5" and info(3,6)<>"6" then goto skip

rem ' Google Fonts test ("Bungee Spice" selected because it's distinctive)
rem ' https://fonts.google.com/specimen/Bungee+Spice?query=bungee+spice

rem <link rel="preconnect" href="https://fonts.googleapis.com">
rem <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
rem <link href="https://fonts.googleapis.com/css2?family=Bungee+Spice&display=swap" rel="stylesheet">

rem ' Firefox tracking protection can block Google Fonts:
rem ' https://developer.mozilla.org/en-US/docs/Web/Privacy/Firefox_tracking_protection

web! = bbjapi().getWebManager()
web!.setCallback(web!.ON_LINK_LOADED,"event")
web!.setCallback(web!.ON_LINK_FAILED,"event")

bbjapi().getWebManager().injectLinkUrl("https://fonts.googleapis.com",1,"rel=""preconnect""")
bbjapi().getWebManager().injectLinkUrl("https://fonts.gstatic.com",1,"rel=""preconnect""")
url$ = "https://fonts.googleapis.com/css2?family=Bungee+Spice&display=swap"
top = 1
attr$ = "rel=""stylesheet"""
bbjapi().getWebManager().injectLinkUrl(url$,top,attr$)
skip:
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
width = 500, height = 400
title$ = "BBjFontChooser"
window! = sysgui!.addWindow(25,25,width+50,height+100,title$,$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.setCallback(window!.ON_RESIZE,"resize")
fontchooser! = window!.addFontChooser(101,25,25,width,height)
fontchooser!.setCallback(fontchooser!.ON_FONTCHOOSER_CHANGE,"change")
fontchooser!.setCallback(fontchooser!.ON_FONTCHOOSER_APPROVE,"approve")
fontchooser!.setCallback(fontchooser!.ON_FONTCHOOSER_CANCEL,"cancel")
rem fontchooser!.setCallback(fontchooser!.ON_GAINED_FOCUS,"event")
rem fontchooser!.setCallback(fontchooser!.ON_LOST_FOCUS,"event")
rem fontchooser!.setCallback(fontchooser!.ON_MOUSE_ENTER,"event")
rem fontchooser!.setCallback(fontchooser!.ON_MOUSE_EXIT,"event")
fontchooser!.setPreviewMessage("The quick brown fox jumps over the lazy dog.")
button! = window!.addButton(1,width+25-120,height+50,120,25,"Random",$$)
button!.setCallback(button!.ON_BUTTON_PUSH,"random")
status! = window!.addStatusBar(99)
families! = fontchooser!.getFontFamilies()
rem i = msgbox(str(families!),0,"getFontFamilies")
sizes! = fontchooser!.getFontSizes()
rem i = msgbox(str(sizes!),0,"getFontSizes")
families! = new BBjVector()
restore families
while 1
  dread family$,err=*break
  if family$ = "" then break
  families!.add(family$)
wend
rem i = msgbox(str(families!),0,"setFontFamilies")
fontchooser!.setFontFamilies(families!)
sizes! = new BBjVector()
restore sizes
while 1
  dread size,err=*break
  if size = 0 then break
  sizes!.add(size)
wend
rem i = msgbox(str(sizes!),0,"setFontSizes")
fontchooser!.setFontSizes(sizes!)
gosub random
rem families! = fontchooser!.getFontFamilies()
rem i = msgbox(str(families!),0,"getFontFamilies")
rem sizes! = fontchooser!.getFontSizes()
rem i = msgbox(str(sizes!),0,"getFontSizes")
dim event$:tmpl(sysgui)
process_events
families:
data "Andale Mono", "Arial", "Bungee Spice", "Comic Sans MS", "Courier New", "Cursive", "Fantasy", "Georgia", "Impact", "Monospace", "Sans-Serif", "Serif", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana", "Webdings", ""
sizes:
data 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 0
eoj:
  release
status:
  status!.setText(status$)
  print status$
  System.err.println(status$)
return
resize:
  event! = sysgui!.getLastEvent()
  fontchooser!.setSize(event!.getWidth()-50,event!.getHeight()-80)
  button!.setLocation(event!.getWidth()-120-25,event!.getHeight()-30)
  status$ = event!.getEventName()+" width="+str(event!.getWidth())+",height="+str(event!.getHeight())
  gosub status
return
random:
  families! = fontchooser!.getFontFamilies()
  family$ = families!.get(rnd(families!.size()))
  size = sizes!.get(rnd(sizes!.size()))
  style = rnd(4)
  font! = sysgui!.makeFont(family$,size,style)
  status$ = "setSelectedFont "+str(font!)
  gosub status
  fontchooser!.setSelectedFont(font!)
return
change:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  status$ = event$+": "+str(event!.getFont())
  gosub status
return
approve:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  status$ = event$+": "+str(event!.getFont())
  gosub status
return
cancel:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  status$ = event$
  gosub status
return
event:
  event! = sysgui!.getLastEvent()
  event$ = sysgui!.getLastEventString()
  event$ = event.code$+" "+event!.getEventName()
  event$ = event$ + " " + event!.getUrl(err=*next)
  status$ = event$
  gosub status
return
def fnmode$(mode$)
  if mode$="0" then return "Fat Client"
  if mode$="1" then return "Thin Client"
  if mode$="2" then return "Java Applet"
  if mode$="3" then return "Java Web Start"
  if mode$="4" then return "JavaBBjBridge"
  if mode$="5" then return "BUI (Browser)"
  if mode$="6" then return "DWC (Browser)"
  return mode$
fnend

ClosedVersion History

  • BBj 22.03: BBjWebManager::injectLinkUrl added.

See Also

BBjAPI

BBjSysGui

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