Adding a code with .js file to wix website

Question:
How can i add this code type=“text/javascript” id=“mox-voorraad” src=“https://sites.mobilox.nl/voorraad.js” data-url=“Autobedrijf Voorbeeld”></script
to a wix website

Hi, @user5384 !!

I think it depends on what the JavaScript code is meant to do. :thinking:

1 Like

It needs to create a connection between my inventory management via an external party and present it on my Wix website. This can be done using an iframe, but that is not an ideal solution.

You maybe should read that one …

If you do not want to use an iFrame, you still have the option to use a CUSTOM-ELEMENT.
If you do not want to use a custom element and you want to work directly on your page, you still have the option to use CUSTOM-CODE inside of the DASHBOARD-SETTINGS.

And if you don’t want to use any of those 3-possible solutions, you still can do by using the HTTP-FUNCTIONS.JS + YOUR OWN GENERATED SERVER → POLLING-SOLUTION.

How does it work?

  1. You generate a smal server (running local on your own machine)
  2. You expose some of Wix-HTTP-Functions
  3. Your generted SERVER → will poll data peridiocally (let’s say every 5 seconds).
  4. If data changes on wix site → your server recognizes this changes → now your server can react and can do what ever you want!!!

a) starting a function on your server
b) sending back some data to Wix
c) Starting a HTTP-FUNCTION on Wix side.
d) …or doing what ever you want.

And by the way —> Wix do not like push-messages (pushing data to Wix server) for example SSE —>

When working with Server-Sent Events (SSE), the push mode process that sends data to clients is typically referred to as “emitting events” or “streaming events”. In SSE terminology, the server pushes messages to the client over an open HTTP connection using a specific format.

Push vs Polling in Context

  • SSE Push Mode
    • The server automatically sends updates to the client without being asked each time.
    • Example: A live stock ticker or chat messages being streamed.
  • Polling
    • The client must repeatedly ask the server:

“Do you have new data now? How about now? … now?”

  • Example: Refreshing a notifications count every 5 seconds.

I tried the PUSH-MODE several times, and Wix do not like SSE-MODE !!!

With a Custom Element, the script doesn’t display anything on the website.
With Custom Code, the data is shown, but only either above the header or below the footer.
When clicking through in the code, it doesn’t stay on the page but instead opens a separate link to the data URL.

What can I do about this?

Without a provided code, anybody can see what is happening on your page (site).