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
.
function getRouterData(): object;
import wixWindowFrontend from "wix-window-frontend";
// ...
let routerData = wixWindowFrontend.getRouterData();
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:
onClick
event handler that calls openLightbox()
.If you pass data to a lightbox, call the getContext()
method in the lightbox's code to access the received data.
Notes:
openLightbox()
. You can find the lightbox's name by selecting the lightbox and clicking the settings button.openLightBox()
after the onReady()
method, once all page elements have finished loading.function openLightbox(name: string, data: object): Promise<object>;
The name of the lightbox to open.
The data to pass to the lightbox.
import wixWindowFrontend from "wix-window-frontend";
// ...
wixWindowFrontend.openLightbox("LightboxName");
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.
function openModal(url: string, options: OpenModalOptions): Promise<void>;
The URL of the page to show in the modal window.
Modal window options.
import wixWindowFrontend from "wix-window-frontend";
// ...
wixWindowFrontend.openModal("https://en.wikipedia.org/wiki/Wix.com", {
width: 750,
height: 500,
});
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.
function postMessage(message: object, target: string): Promise<object>;
The message to send.
The target to send the message to. Must be "parent"
or omitted. Default: "parent"
.
/* * * * * * * * * * * * * * * * * * * * * * *
* 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;
* } );
*/
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.
function scrollBy(x: number, y: number): Promise<void>;
The horizontal offset, in pixels, to scroll by.
The vertical offset, in pixels, to scroll by.
import wixWindowFrontend from "wix-window-frontend";
// ...
wixWindowFrontend.scrollBy(100, 500);