BBjHtmlView::setUserAgent

Description

In BBj 15.00 and higher, this method sets the user agent string for this BBjHtmlView control.

Syntax

Return Value

Method

void

setUserAgent(string userAgent)

Parameters

Variable

Description

string

The user agent string to be used for the BBjHtmlView control.

Return Value

None.

Remarks

For more information about the user agent string, go to useragentstring.com.

Example

rem ' BBjHtmlView::getUserAgent

url$ = "https://www.whatismybrowser.com/detect/what-is-my-user-agent/"

client = 0
if (info(3,6)<>"5" and info(3,6)<>"6") 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,800,700,"htmlview "+url$,$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.setCallback(window!.ON_RESIZE,"resize")
getUserAgent! = window!.addButton(1,25,25,150,25,"getUserAgent",$$)
getUserAgent!.setCallback(getUserAgent!.ON_BUTTON_PUSH,"getUserAgent")
text! = window!.addEditBox(100,200,25,575,25,"",$0200$)
setUserAgent! = window!.addButton(2,25,75,150,25,"setUserAgent",$$)
setUserAgent!.setCallback(setUserAgent!.ON_BUTTON_PUSH,"setUserAgent")
edit! = window!.addEditBox(101,200,75,575,25,"",$$)
htmlview! = window!.addHtmlView(102,25,125,750,550,"",$$)
gosub display

process_events

eoj:
release

display:
  if htmlview!.getClientType()="Chromium" then
     htmlview!.setUrl(url$)
  else
     js$ = "navigator.userAgent"
     userAgent$ = str(htmlview!.executeScript(js$))
     text$ = js$ + " = " + userAgent$
     htmlview!.setText(text$)
  endif
return

resize:
  event! = sysgui!.getLastEvent()
  htmlview!.setSize(event!.getWidth()-50,event!.getHeight()-150)
return

getUserAgent:
  useragent$ = htmlview!.getUserAgent()
  text!.setText(useragent$)
return

setUserAgent:
  htmlview!.setText("")
  htmlview!.setUserAgent(edit!.getText())
  gosub display
return

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

BBjHtmlView::getUserAgent

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