Introduction

To use the window module, import wixWindowFrontend from the wix-window-frontend module:

Copy
import wixWindowFrontend from "wix-window-frontend";

The APIs in wix-window-frontend can only be used in frontend code.

Learn more about wix-window-frontend in Getting Started and on Wix Learn.

Did this help?

App Page Data

You can use the getAppPageData() method for custom app pages to retrieve data you can use to customize the page. The data passed to each type of custom app page is different. This article lists the objects passed to each type of custom app page.

Booking Service Page

The object passed to a custom Booking Service page contains the following properties:

NameTypeDescription
serviceObjectThe Service object, which contains detailed data about the service.

Note: If the page URL specifies a service that is deleted, hidden, or does not exist, the app returns null.

Learn more about building a custom Service page.

Booking Calendar Page

The object passed to a custom Booking Calendar page contains the following properties:

NameTypeDescription
serviceObjectThe Service object, which contains detailed data about the service.

Pricing Plans Page

The object passed to a custom Pricing Plans page contains the following properties:

NameTypeDescription
planObjectThe Plan object, which contains detailed data about the plans.

Note: If the page URL specifies a plan that is deleted, hidden, or does not exist, the app returns null.

Learn more about building a custom Pricing Plans page.

Did this help?

browserLocale


browserLocalestringRead-only

Gets the locale of a site visitor's browser.

A locale, also known as an IETF language tag, is an abbreviated code that defines the language, country, and other aspects of a site visitor's browser, such as number format and date format.

Some common locales include:

  • "en-US": English, United States
  • "en-GB": English, British
  • "es-ES": Spanish, Spain
  • "de-DE": German, Germany
  • "ja-JP": Japanese, Japan
  • "fr-CH": French, Switzerland
  • "it-IT": Italian, Italy
Get the locale of a site visitor's browser
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... let browserLocale = wixWindowFrontend.browserLocale; // "en-US"
Did this help?

formFactor


formFactorstringRead-only

Gets what kind of device is being used to view a page.

Note: This property only checks a site visitor's device, and not which Studio Editor's breakpoint they are using.

The formFactor property gets one of:

  • "Desktop": When viewed in a desktop browser.
  • "Mobile": When viewed in a mobile browser.
  • "Tablet": When viewed in a tablet browser.

Important: Some tablet devices (such as iPads) are identified in this property as "Desktop".

Get a device's form factor
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... let formFactor = wixWindowFrontend.formFactor; // "Mobile"
Did this help?

referrer


referrerstringRead-only

Gets the HTTP referrer header field.

The referrer is the address of the web page a site visitor was previously on before arriving at the current page, typically by clicking a link.

Note: When site visitors move from page to page within your site, the referrer property does not contain the address of the page the site visitor came from. This is because Wix sites are built as single page applications. To get the previous page a site visitor was visiting within your site, you can use wix-storage-frontend to store the visitor's current page and retrieve the visitor's previous page.

JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... let referrer = wixWindowFrontend.referrer; // "http://somesite.com"
Did this help?

viewMode


viewModestringRead-only

Gets which mode a site is currently being viewed in.

The viewMode property gets either:

  • "Preview": When previewing a site using the Preview button in the editor.
  • "Site": When viewing a published site.
  • "Editor": When viewing a Wix Blocks built widget in the editor.
Get a window's view mode
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... let viewMode = wixWindowFrontend.viewMode; // "Site"
Did this help?

copyToClipboard( )


Copies text to a site visitor's clipboard.

The copyToClipboard() method copies the specified text to a site visitor's clipboard.

If a site visitor's browser doesn't support copying text to the clipboard programmatically, a modal popup that allows copying will be displayed. For example, when calling copyToClipboard() from a Firefox or Edge browser, a site visitor will see something similar to the popup shown below.

Copy To Clipboard Popup

The Promise returned by copyToClipboard() resolves when the specified text is copied to clipboard or the modal popup is closed. The Promise is rejected if a null value is passed as the toCopy parameter or if a site visitor's browser blocks the modal popup from opening.

Method Declaration
Copy
function copyToClipboard(text: string): Promise<void>;
Method Parameters
textstringRequired

The text to copy.

Copy text to clipboard
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend .copyToClipboard("Text to copy!") .then(() => { // handle case where text was copied }) .catch((err) => { // handle case where an error occurred });
Did this help?

getAppPageData( )


Gets the data passed to a custom app page.

Wix passes data to custom app pages that you can use when implementing a page's business logic. Call the getAppPageData() method to retrieve the data and use it in your code. The data retrieved by this method is different for each type of custom app page. For more information, see App Page Data.

Learn more about building custom app pages.

Note: If you call getAppPageData() for a page that isn't a custom app page, it returns null.

Method Declaration
Copy
function getAppPageData(): object;
Request
This method does not take any parameters
Returns
Return Type:
Get the data passed to a custom app page
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... let appData = wixWindowFrontend.getAppPageData(); // {nextSection: {sectionId: "Booking Form"}}
Did this help?

getBoundingRect( )


Gets information about a window.

Returns information about a window's size, document's size, and current scroll position.

This method returns null for sites with SSR.

Method Declaration
Copy
function getBoundingRect(): Promise<WindowSizeInfo>;
Request
This method does not take any parameters
Returns
Return Type:Promise<WindowSizeInfo>
Get information about a window
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.getBoundingRect().then((windowSizeInfo) => { let windowHeight = windowSizeInfo.window.height; // 565 let windowWidth = windowSizeInfo.window.width; // 1269 let documentHeight = windowSizeInfo.document.height; // 780 let documentWidth = windowSizeInfo.document.width; // 1269 let scrollX = windowSizeInfo.scroll.x; // 0 let scrollY = windowSizeInfo.scroll.y; // 120 });
Did this help?

getCurrentGeolocation( )


Gets the current geolocation of a site visitor.

The getCurrentGeolocation() method has the following limitations:

  • On Chrome, the function only works on HTTPS sites.
  • On Chrome, Firefox, and Safari, the function only works if the site visitor approves a popup. If they do not approve, the promise is rejected.
  • Run getCurrentGeolocation() with a setTimeout() in case the browser is set to not detect the locale. Adding the timeout lets you handle the unfulfilled promise.
Method Declaration
Copy
function getCurrentGeolocation(): Promise<CurrentGeolocation>;
Request
This method does not take any parameters
Returns
Return Type:Promise<CurrentGeolocation>
Get the geolocation data
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend .getCurrentGeolocation() .then((obj) => { let timestamp = obj.timestamp; // 1495027186984 let latitude = obj.coords.latitude; // 32.0971036 let longitude = obj.coords.longitude; // 34.774391099999995 let altitude = obj.coords.altitude; // null let accuracy = obj.coords.accuracy; // 29 let altAccuracy = obj.coords.altitudeAccuracy; // null let heading = obj.coords.heading; // null let speed = obj.coords.speed; // null }) .catch((error) => { let errorMsg = error; });
Did this help?

getRouterData( )


Gets the data sent by a router to a page as part of its response.

When you define a router and its functionality in the router() method, you can include data in the router's response. This data can then be accessed in the code of the routed page by calling the getRouterData() method. If you call this method from a non-router page or a router page that wasn't sent any data, the method returns null.

Method Declaration
Copy
function getRouterData(): object;
Request
This method does not take any parameters
Returns
Return Type:
Get the data sent by a router
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... let routerData = wixWindowFrontend.getRouterData();
Did this help?

openLightbox( )


Opens a lightbox and optionally passes it the given data.

The openLightbox() method opens a lightbox and allows you to pass data to it. Lightboxes that are opened automatically on page load, or via a link from a page element don't receive passed data.

To ensure data can be passed:

  1. Call this method to open a lightbox programmatically. For example, add a button with an onClick event handler that calls openLightbox().
  2. Set Automatically display lightbox on pages to No in the lightbox's settings under Set Triggers.

If you pass data to a lightbox, call the getContext() method in the lightbox's code to access the received data.

Notes:

  • Use the name of the lightbox and not the lightbox's ID when calling openLightbox(). You can find the lightbox's name by selecting the lightbox and clicking the settings button.
  • Only call openLightBox() after the onReady() method, once all page elements have finished loading.
Method Declaration
Copy
function openLightbox(name: string, data: object): Promise<object>;
Method Parameters
namestringRequired

The name of the lightbox to open.


dataData

The data to pass to the lightbox.

Returns
Return Type:Promise<object>
JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.openLightbox("LightboxName");
Did this help?

openModal( )


Opens a modal window that displays the specified web page.

A modal window displays the page specified by the url property over your current page. Unlike a lightbox, which is opened by calling the openLightbox() method, a window opened by openModal() is not part of a site's structure.

Only one modal window can be open at any given time. Therefore, opening a modal window closes an already open modal window if there is one.

Note: The specified url must be an HTTPS URL.

Method Declaration
Copy
function openModal(url: string, options: OpenModalOptions): Promise<void>;
Method Parameters
urlstringRequired

The URL of the page to show in the modal window.


optionsOpenModalOptionsRequired

Modal window options.

JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.openModal("https://en.wikipedia.org/wiki/Wix.com", { width: 750, height: 500, });
Did this help?

postMessage( )


Sends a message to a page's parent.

If a page is embedded within another site, using an HtmlComponent on a Wix site or an iframe on a non-Wix site, call this method to send a message from the inner site to the outer site.

When the parent site is a Wix site, call onMessage() to receive the message on the parent page.

When the parent site is a non-Wix site, use the page's window.onMessage event handler to read the data property of the received MessageEvent to receive the message on the parent page.

Method Declaration
Copy
function postMessage(message: object, target: string): Promise<object>;
Method Parameters
messageMessageRequired

The message to send.


targetstring

The target to send the message to. Must be "parent" or omitted. Default: "parent".

Returns
Return Type:Promise<object>
JavaScript
/* * * * * * * * * * * * * * * * * * * * * * * * Code for the inner site to post a message * * * * * * * * * * * * * * * * * * * * * * * */ import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.postMessage(dataObj); /* * * * * * * * * * * * * * * * * * * * * * * * * * Code for the outer site to receive a message * * * * * * * * * * * * * * * * * * * * * * * * * * * * $w("#myHtmlComponent").onMessage( (event, $x) => { * let message = event.data; * } ); */
Did this help?

scrollBy( )


Scrolls a page by the specified number of pixels.

The x and y parameters determine the number of horizontal and vertical pixels to scroll the current page. Negative numbers scroll up or to the left and positive numbers scroll down or to the right.

Method Declaration
Copy
function scrollBy(x: number, y: number): Promise<void>;
Method Parameters
xnumberRequired

The horizontal offset, in pixels, to scroll by.


ynumberRequired

The vertical offset, in pixels, to scroll by.

JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.scrollBy(100, 500);
Did this help?

scrollTo( )


Scrolls a page to the specified location.

The x and y parameters determine the top-left pixel that is displayed on screen after the scroll.

Tip: To get the coordinates for scrolling, click on an element to open the Inspector panel (Wix Studio), or open the Editor toolbar (Wix Editor). Then move the cursor to the top-left pixel where you want the page to scroll to. The X and Y axis Position values show the coordinates.

Use the options parameter to specify the options to use when scrolling.

Method Declaration
Copy
function scrollTo(
  x: number,
  y: number,
  options: ScrollToOptions,
): Promise<void>;
Method Parameters
xnumberRequired

The horizontal position, in pixels, to scroll to.


ynumberRequired

The vertical position, in pixels, to scroll to.


optionsScrollToOptions

Scrolling options.

JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.scrollTo(100, 500);
Did this help?

trackEvent( )


Sends a tracking event to external analytics tools.

Sends an event to analytics tools connected to your site. It can send events to Google Analytics, Facebook Pixel or analytics tools set up with the Google Tag Manager.

Learn more about:

Note: This method only runs on published versions of your site. It doesn't work when previewing your site.

The trackEvent() method lets you track both standard and custom events.

The following standard events are supported:

Standard EventDescriptionUsed By
AddPaymentInfoWhen a site visitor saves payment information.Google Analytics, Facebook Pixel
AddProductImpressionWhen a site visitor views a product.Google Analytics
AddToCartWhen a site visitor adds a product to the shopping cart.Google Analytics, Facebook Pixel
CheckoutStepWhen a site visitor completes a checkout step.Google Analytics
ClickProductWhen a site visitor clicks on a product.Google Analytics
CompleteRegistrationWhen a site visitor completes the registration. Note: The CompleteRegistration event doesn't take any parameters.Facebook Pixel
InitiateCheckoutWhen a site visitor starts the checkout process.Google Analytics, Facebook Pixel
LeadWhen a site visitor subscribes to a newsletter or submits a contact form.Google Analytics, Facebook Pixel
PurchaseWhen the customer successfully completes the checkout process.Google Analytics, Facebook Pixel
RemoveFromCartWhen a site visitor removes a product from the shopping cart.Google Analytics
ScheduleWhen a site visitor schedules a meeting or makes an appointment. Note: The Schedule event doesn't take any parameters.Facebook Pixel
StartPaymentWhen a site visitor starts the payment process.Google Analytics
ViewContentWhen a site visitor views a key page, for example the product page.Google Analytics, Facebook Pixel
Method Declaration
Copy
function trackEvent(eventName: string, parameters: union): void;
Method Parameters
eventNamestringRequired

Event name. Applies to both standard and custom events. The following standard events are supported:

  • AddPaymentInfo
  • AddProductImpression
  • AddToCart
  • CheckoutStep
  • ClickProduct
  • CompleteRegistration
  • InitiateCheckout
  • Lead
  • Purchase
  • RemoveFromCart
  • Schedule
  • StartPayment
  • ViewContent

parametersunionRequired

The event's parameters. Note: The CompleteRegistration and Schedule events don't take any parameters.

JavaScript
import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.trackEvent("Lead");
Did this help?