top of page
Hello HTML Component

Hello HTML Component

Get started with HTML Components.

Intermediate.png

Beginner

2K

Published:

February 26, 2023

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

HTML Components allow you to embed an HTML iFrame in a page. In this example, we demonstrate sending information from the page to the HTML Component and from the HTML Component to the page.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Page Elements


We split the HOME page into 2 sections.


The top section contains regular Wix elements. It has 2 text elements: one is used as a label and the other is used to display information passed to the page from the HTML Component. This section also contains a button used to send a message to the HTML Component.


The bottom section contains an HTML Component. Inside the component, we use HTML, CSS, and JavaScript to create 2 text elements and a button. One text element is used as a label and the other is used to display information passed to the HTML Component from the page. The button used is used to send a message to the page.


Page Code


We added 2 event handlers to the HOME page.


The first event handler runs when the button to send messages from the page to the HTML Component is clicked. It uses the Wix `postMessage()` function to send the message.


The second event handler runs when a message is received from the HTML Component. It populates the received message into the text element with the ID `message`.

HTML Component Code

The HTML Component includes code for creating and designing its UI elements. It also contains two event handlers.


The first event handler runs when a message is received from the page. It populates the received message into the text element with the ID `message`.


The second event handler runs when the button to send messages from the HTML Component to the page is clicked. It uses the non-Wix `postMessage()` function to send the message. Note that in a production environment, you should always specify the URL of your site as the target origin (the second argument of the `postMessage()` function) and not "*".

APIs We Used

Non-code example.

Related Articles

Article Link

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Image placeholder.png

Add to Cart Gallery

Let customers to add products to their cart

Intermediate.png

INTERMEDIATE

Image placeholder.png

Hide and Show Elements

Hide and show elements in response to user interactions

Begginer.png

BEGGINER

Image placeholder.png

Hide and Show Elements

Hide and show elements in response to user interactions

Begginer.png

BEGGINER

Anchor 2
bottom of page