The
Browser object accesses features of the web browser running the HTML5 game. It also switch to and from fullscreen mode, detect if the game is updating in the background, and determine if the page is visible.
Security limitations sometimes prevent browser actions. For example, the window
Close action can only be used when the window was created by a javascript
window.open call.
Browser conditions
Cookies enabledTrue if the user has cookies enabled in their browser. (Typically it is rare for them to be disabled since many web sites rely on cookies to work properly.)
Is onlineTrue if the browser currently has an active connection to the internet. Construct 2 games can work offline - see
Offline games for more information.
On went onlineOn went offlineTriggered if the connection to the internet is becomes available or unavailable during the running of the game. This is common on mobile devices which may be moving in and out of signal areas. The
Is online condition also changes to reflect the connection status.
On menu buttonCurrently only supported when exporting to PhoneGapTriggered when the user presses the device's 'Menu' button. Note not all devices have this button, e.g. iOS devices only have a 'Home' button.
On search buttonCurrently only supported when exporting to PhoneGapTriggered when the user presses the device's 'Search' button. Note not all devices have this button, e.g. iOS devices only have a 'Home' button.
Is downloading updateTrue if the game is running from cache, but downloading an updated version in the background. This can be used to implement a simple auto-updater. See
Offline games for more information.
On update readyTriggered when the game is running from cache, but an updated version has finished downloading in the background. If the user is still on the game's menu or title screen, you may wish to prompt them to refresh the page (or just do it automatically) so the new version is loaded. See
Offline games for more information.
Is fullscreenTrue if the browser is running in fullscreen mode.
Page is visibleTrue if the page the HTML5 game is running on is currently visible. The page counts as hidden if the window is minimised, the page is in a different tab to the one being viewed, or on a mobile device when the app goes in to the background. When the page is hidden the game automatically pauses.
On suspendedOn resumedTriggered when the page's visibility changes, or when a mobile app is going in to the background or foreground. When invisible or in the background the app is suspended: all events stop running and all audio is muted.
Browser actions
Go backGo forwardMove through the browser navigation history as if clicking the Back and Forward buttons on the browser.
Go homeNavigate to the browser's set homepage.
Go to URLNavigate to a given URL. Note this uses the same window/tab as is showing the HTML5 game, so this action will end the game.
Open URL in new windowNavigate to a given URL in a new window (or tab if the browser settings override). This continues to run the HTML5 game in the old window or tab.
ReloadForce the page to refresh. This effectively restarts the game.
AlertBring up a simple 'alert' message box.
BlurUnfocus the browser window.
Cancel fullscreenReturn to windowed mode if the browser is currently in fullscreen mode.
CloseClose the current window, if the script has permission to do so.
FocusFocus the browser window.
Request fullscreenRequest that the browser enter fullscreen mode. Note the browser may ignore this request unless the action is in a user-initiated event, such as a mouse click, key press, touch event or button press. There are three different fullscreen modes that can be entered:
Center - center the game viewport in the fullscreen view
Stretch (crop) - extend the game viewport to fill the fullscreen view
Stretch (scale) - scale (zoom) the game viewport to fill the fullscreen view
The latter two options correspond to the
Fullscreen in browser project property. For more information see
supporting multiple screen sizes.
Browser expressions
LangageGet the browser's current language setting, e.g.
en-US.
NameGet the name the browser reports for itself. This may be inaccurate for backwards compatibility reasons, e.g. Google Chrome reports its name as
Netscape.
PlatformGet the current platform the browser reports itself running on, e.g.
Win32 for Windows.
ProductGet the product the browser reports for itself. This may be inaccurate for backwards compatibility reasons, e.g. Google Chrome reports its product as
Gecko.
UserAgentReturn the full user agent string for the browser, e.g.
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63.
VendorGet the vendor the browser reports for itself, e.g.
Google Inc. for Google Chrome.
VersionGet the version the browser reports for itself as a string. This can simply be a subset of the user agent string.
TitleThe current HTML document's title.
DomainThe current domain, e.g.
scirra.com.
HashThe string after the hash at the end of the URL, including the hash. For example, if the current URL is
http://scirra.com/mygame/index.html#teapot, this returns
#teapot.
PathNameThe path relative to the domain in the URL. For example the path name of
http://scirra.com/mygame/index.html#teapot is
/mygame/index.html.
ProtocolThe current protocol, usually either
http: or
https:.
QueryParamReturn a query string parameter by name. For example, if the URL ends with
index.html?foo=bar&baz=wan,
QueryParam("foo") returns
bar and
QueryParam("baz") returns
wan.
QueryStringReturn the full URL query string including the question mark. For example, if the URL ends with
index.html?foo=bar&baz=wan, this returns
?foo=bar&baz=wan.
ReferrerGet the previous page that linked to this page, if any.
URLGet the complete current URL in the browser address bar, including the protocol.