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?