Window

window/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, useCaptureopt)

Source:
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 Attributes 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) → {CustomEvent}

Source:
See:
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.
Returns:
The created custom event.
Type
CustomEvent

getBody() → {undefined|HTMLBodyElement}

Source:
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() → {undefined|Document}

Source:
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() → {string}

Source:
Returns the domain of the current document's URL as `${protocol://${host}`}.
Returns:
The current domain.
Type
string

getElementById(id) → (nullable) {HTMLElement}

Source:
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

getHost() → {string}

Source:
Returns the application's host.
Returns:
The current host.
Type
string

getPath() → {string}

Source:
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() → {number}

Source:
Returns the number of pixels the viewport is scrolled horizontally.
Returns:
The number of pixels the viewport is scrolled horizontally.
Type
number

getScrollY() → {number}

Source:
Returns the number of pixels the document is scrolled vertically.
Returns:
The number of pixels the document is scrolled vertically.
Type
number

getUrl() → {string}

Source:
Returns the current document's URL.
Returns:
The current document's URL.
Type
string

getWebSocket() → {function}

Source:
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 to use.
Returns:
The current WebSocket implementation.
Type
function

getWindow() → {undefined|Window}

Source:
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

hasHistoryAPI() → {boolean}

Source:
Deprecated:
  • The history API should never be manipulated directly in an IMA.js application, and all browsers supported by IMA.js support the history API.
Returns true if the history manipulation API is supported.
Returns:
true if the history manipulation API is supported.
Type
boolean

hasSessionStorage() → {boolean}

Source:
Returns true if the session storage is supported.
Returns:
true if the session storage is supported.
Type
boolean

hasWebSocket() → {boolean}

Source:
Deprecated:
  • All browsers currently supported by IMA.js support web sockets.
Returns true if the WebSockets are supported.
Returns:
true if the WebSockets are supported.
Type
boolean

isClient() → {boolean}

Source:
Returns true if invoked at the client side.
Returns:
true if invoked at the client side.
Type
boolean

isCookieEnabled() → {boolean}

Source:
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)

Source:
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) → (nullable) {HTMLElement}

Source:
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) → {NodeList}

Source:
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)

Source:
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)

Source:
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)

Source:
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)

Source:
Sets the new page title of the document.
Parameters:
Name Type Description
title string The new page title.

unbindEventListener(eventTarget, event, listener, useCaptureopt)

Source:
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 Attributes 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.