Interface: Window

Window

The Window interface defines various utility API for easier cross-environment usage of various low-level client-side JavaScript APIs available through various global objects.

Methods


bindEventListener(eventTarget, event, listener [, useCapture])

Registers the provided event listener to be executed when the specified event occurs on the specified event target.

Registering the same event listener for the same event on the same event target with the same useCapture flag value repeatedly has no effect.

Parameters:
Name Type Argument Default Description
eventTarget EventTarget

The event target.

event string

The name of the event.

listener function

The event listener.

useCapture boolean <optional>
false

If true, the method initiates event capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree. Events which are bubbling upward through the tree will not trigger a listener designated to use capture.


createCustomEvent(name, options)

Create new instance of CustomEvent of the specified name and using the provided options.

Parameters:
Name Type Description
name string

Custom event's name (sometimes referred to as the event's type).

options Object.<string, *>

The custom event's options.

See:
Returns:

The created custom event.

Type
CustomEvent

getBody()

Returns the document's body element. The method returns undefined if invoked at the server-side.

Returns:

The document's body element, or undefined if invoked at the server side.

Type
undefined | HTMLBodyElement

getDocument()

Returns the native document object representing any web page loaded in the browser and serves as an entry point into the web page's content which is the DOM tree at the client-side. The method returns undefined if used at the server-side.

Returns:

The document object at the client-side, or undefined at the server-side.

Type
undefined | Document

getDomain()

Returns the domain of the current document's URL as ${protocol</code>://${host}}.

Returns:

The current domain.

Type
string

getElementById(id)

Returns the HTML element with the specified id attribute value.

Parameters:
Name Type Description
id string

The value of the id attribute to look for.

Returns:

The element with the specified id, or null if no such element exists.

Type
HTMLElement

getHistoryState()

Returns the history state.

Returns:

The current history state

Type
Object

getHost()

Returns the application's host.

Returns:

The current host.

Type
string

getPath()

Returns the path part of the current URL, including the query string.

Returns:

The path and query string parts of the current URL.

Type
string

getScrollX()

Returns the number of pixels the viewport is scrolled horizontally.

Returns:

The number of pixels the viewport is scrolled horizontally.

Type
number

getScrollY()

Returns the number of pixels the document is scrolled vertically.

Returns:

The number of pixels the document is scrolled vertically.

Type
number

getUrl()

Returns the current document's URL.

Returns:

The current document's URL.

Type
string

getWebSocket()

Returns the current WebSocket implementation to use.

Deprecated:
  • All browsers currently supported by IMA.js support web sockets, but when used at the server-side, this method should fail unless web sockets are polyfilled by a 3rd party library.
Returns:

The current WebSocket implementation.

Type
function

getWindow()

Returns the native window object representing the global context at the client-side. The method returns undefined if used at the server-side.

Returns:

The window object at the client-side, or undefined at the server-side.

Type
undefined | Window

hasSessionStorage()

Returns true if the session storage is supported.

Returns:

true if the session storage is supported.

Type
boolean

isClient()

Returns true if invoked at the client side.

Returns:

true if invoked at the client side.

Type
boolean

isCookieEnabled()

Returns true if the cookies are set and processed with every HTTP request and response automatically by the environment.

Returns:

true if cookies are handled automatically by the environment.

Type
boolean

pushState(state, title, url)

Pushes a new state to the browser history. The method has no effect if the current browser does not support the history API (IE9).

Parameters:
Name Type Description
state Object.<string, *>

A state object associated with the history item, preferably representing the page state.

title string

The page title related to the state. Note that this parameter is ignored by some browsers.

url string

The new URL at which the state is available.


querySelector(selector)

Returns the first element matching the specified CSS 3 selector.

Parameters:
Name Type Description
selector string

The CSS selector.

Returns:

The first element matching the CSS selector or null if no such element exists.

Type
HTMLElement

querySelectorAll(selector)

Returns a node list of all elements matching the specified CSS 3 selector.

Parameters:
Name Type Description
selector string

The CSS selector.

Returns:

A node list containing all elements matching the specified CSS selector.

Type
NodeList

redirect(url)

Performs a hard redirect (discarding the current JavaScript state) to the specified URL.

Parameters:
Name Type Description
url string

The URL to which the browser will be redirected.


replaceState(state, title, url)

Replaces the current history entry. The method has no effect if the current browser does not support the history API (IE9).

Parameters:
Name Type Description
state Object.<string, *>

A state object associated with the history item, preferably representing the page state.

title string

The page title related to the state. Note that this parameter is ignored by some browsers.

url string

The new URL at which the state is available.


scrollTo(x, y)

Scrolls the viewport to the specified location (if possible).

Parameters:
Name Type Description
x number

Horizontal scroll offset in pixels.

y number

Vertical scroll offset in pixels.


setTitle(title)

Sets the new page title of the document.

Parameters:
Name Type Description
title string

The new page title.


unbindEventListener(eventTarget, event, listener [, useCapture])

Deregisters the provided event listener, so it will no longer we executed when the specified event occurs on the specified event target.

The method has no effect if the provided event listener is not registered to be executed at the specified event.

Parameters:
Name Type Argument Default Description
eventTarget EventTarget

The event target.

event string

The name of the event.

listener function

The event listener.

useCapture boolean <optional>
false

The useCapture flag value that was used when the listener was registered.