lz.BrowserService
Provides access to the browser and player environment

JavaScript: lz.BrowserService

lz.Browser is the single instance of the class lz.BrowserService.

Interface to the browser via the runtime kernel

The lz.Browser service provides access to the browser and player environment. It includes methods to load URLs in the browser, and check the version of the player. For example:

Example 20. Using lz.Browser to launch another browser

<canvas height="140" debug="true">
   <!-- Load the OpenLaszlo site in a new window -->
   <button onclick="lz.Browser.loadURL('http://www.openlaszlo.org/', '_blank')">
     Click me
   </button>
   <script>
     // List the player version
     Debug.debug('Player version: %w', lz.Browser.getVersion());
   </script>
 </canvas>

Class Attributes

Name (CSS property) Type (tag) Type (js) Default Category
LzBrowser   lz.BrowserService   readonly
  The browser service. Also available as the global lz.Browser.

Methods

callJS()
lz.BrowserService.callJS(methodname : String, callback : Function, args);
Runs a Javascript method in the browser, optionally returning the result. Note that this feature requires the application to be embedded by the embed-compressed.js library.
Parameter Name Type Description
methodname String Browser javascript method to execute
callback Function Optional callback function to receive the return value of the javascript call.
args   Optional arguments to call the method with

getAppID()
lz.BrowserService.getAppID();
This function returns the id the app was started with
Returns Type Description
  String The id the app was started with

getInitArg()
lz.BrowserService.getInitArg(name : String);
This function returns values from the the request string that loaded the the lzx app. This can be used to communicate initialization arguments to an lzx app without forcing it to load data.
Parameter Name Type Description
name String The name of the key whose value to return. If null, returns an Object containing all initialization arguments. @return: The value for a key that appears in the request string that loaded the the lzx app or an Object containing all values

getLoadURL()
lz.BrowserService.getLoadURL();
Returns the URL from which the application was loaded.
Returns Type Description
  String the URL the application was loaded from

getLoadURLAsLzURL()
lz.BrowserService.getLoadURLAsLzURL();
Returns the loadUrl as a new LzURL
Returns Type Description
  lz.URL the URL the application was loaded from, as an LzURL

getLzOption()
lz.BrowserService.getLzOption(name : String);
This function returns values from the the lzoptions arg. If the arg name is not found in the lzoptions string, it falls back to look for the name in the regular query args. The arg name is mapped to the old "lz"-style name if needed.
Parameter Name Type Description
name String The name of the key whose value to return. If null, returns an Object containing all initialization arguments. @return: The value for a key that appears in the lzoptions string

getOS()
lz.BrowserService.getOS();
Returns information about the operating system

getURL()
lz.BrowserService.getURL();
Returns the URL in the browser location bar. May return null if called before the app initializes.
Returns Type Description
  String the URL in the browser location bar

getVersion()
lz.BrowserService.getVersion();
Returns version information about the browser

isAAActive()
lz.BrowserService.isAAActive();
Determines if a screen reader is active and the application is focused @return: True if a screen reader is active and the application is focused

loadJS()
lz.BrowserService.loadJS(js : String, target : String);
Runs Javascript in the browser using a javascript: url, optionally in a target window. Note that Flash limits the javascript string to a maximum of 508 characters. See callJS() for a higher-performance alternative.
Parameter Name Type Description
js String Javascript string to execute
target String Optionally specifies a named frame to display the contents of the URL. By default, the javascript specified in 'js' is executed in the current browser frame .

loadURL()
lz.BrowserService.loadURL(url : String, target : String, features : String);
Loads a URL in the browser, optionally in a target
Parameter Name Type Description
url String URL to load
target String Optionally specifies a named frame to display the contents of the URL. Otherwise defaults to the current window.
features String Optional features to use in the new window.

makeProxiedURL()
lz.BrowserService.makeProxiedURL(params);
Parameter Name Type Description
params    

setClipboard()
lz.BrowserService.setClipboard(str : String);
Sets the system clipboard to the specified string
Parameter Name Type Description
str String String to set the system clipboard to

setWindowTitle()
lz.BrowserService.setWindowTitle(str : String);
Sets the browser window title
Parameter Name Type Description
str String String to set the browser window title

showMenu()
lz.BrowserService.showMenu(truefalse : Boolean);
Turns the runtime-specific context menu on or off
Parameter Name Type Description
truefalse Boolean boolean value - true for on, false for off.

urlEscape()
lz.BrowserService.urlEscape(str : String);
[Caution] This method is deprecated
Use encodeURIComponent(string) instead.
Escape a string using URL encoding.
Parameter Name Type Description
str String The string to escape
Returns Type Description
  String An URL escaped string

urlUnescape()
lz.BrowserService.urlUnescape(str : String);
[Caution] This method is deprecated
Use decodeURIComponent(string) instead.
Escape a string using URL encoding.
Parameter Name Type Description
str String The string to unescape
Returns Type Description
  String An URL decoded string

xmlEscape()
lz.BrowserService.xmlEscape(str : String);
Escape the five XML entities in a string (See http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML) Note that if you declare an attribute to be of type `cdata`, then this transformation will automatically happen when you data- or style-bind that attribute
Parameter Name Type Description
str String The string to escape

xmlUnescape()
lz.BrowserService.xmlUnescape(str : String);
Unescape the five XML entities in a string Note that if you declare an attribute to be of type `cdata`, then this transformation will automatically happen when you data-bind that attribute and save the value to the dataset. (See http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML)
Parameter Name Type Description
str String The string to escape