Problem with JavaScript code

Hi!
I’m trying to put simple javascript to my page. Adding with velo or HTML box gives no result. Element doesn’r show up.
Code below. What do I do wrong?

(function() { var s = document.createElement(“script”),e = document.scripts[document.scripts.length - 1];
s.type = “text/javascript”; s.async = true;s.src = “//forms.fcc- http: //online .pl/public/widget.js”;
s.setAttribute(‘charset’, ‘utf-8’);
s.setAttribute(‘data-form-id’, ‘3465d3b0-5a54-4e57-a537-3757f95b93d5’);
e.parentNode.insertBefore(s, e);})();

Several things to point out:

  • You can’t embed HTML in a Velo page, you will need an HtmlComponent or a CustomElement .

  • Your snippet is not complete code and doesn’t seem as if it would do anything on its own.

  • Adding code to an HTML component is not a part of the Velo product (which is what this forum is about). You will need to check with the service provider to find out how to get it work.

  • URLs in the embedded code must begin with https .

I wasn’t precise. Ofcourse, I’m using HTML component. Code itself works on a non wix page. I’m pretty sure it’s ok.

Directly in Valeo code is like below. Debugger says:
„ReferenceError: document is not defined”

$w.onReady
const script = document.createElement(‘script’),
element = document.getElementById(‘ext-form’);
script.src = ‘//forms.fcc-online. pl/public/widget.js’;
script.type = ‘text/javascript’;
script.setAttribute(‘charset’, ‘utf-8’);
script.setAttribute(‘data-form-id’, ‘3465d3b0-5a54-4e57-a537-3757f95b93d5’);
script. async = trueelement?.appendChild(script)

Velo does not allow access to the DOM (window, document, etc) - so that is the reason for the error you are getting.

See the article Velo: Working with the HTML iframe Element for details on how to use an embedded script in an HtmlComponent.

Also… URLs in an embedded script must be https .

Another option that might be more suitable for your widget would be through the Custom Code sections . This option also requires https URLs only.

@yisrael-wix I’ve put that mofo in html element.
Works fine for me.
Thanks gór help.

Hi, I am working Custom FAQ on velo code in Wix, But $w.onReady(function () {
$w(“#iconToggle1”).onClick(() => {
console.log(“Icon clicked”);
if ($w(“#faqAnswer”).collapsed) {
console.log(“Expanding FAQ”);
$w(“#faqAnswer”).expand({ duration: 500 });

  // Rotate the icon 90 degrees when expanding
  $w("#iconToggle1").style.transform = "rotate(90deg)";
  $w("#iconToggle1").style.transition = "transform 0.5s"; // Smooth transition
} else {
  console.log("Collapsing FAQ");
  $w("#faqAnswer").collapse({ duration: 500 });
  
  // Reset icon rotation to 0 degrees when collapsing
  $w("#iconToggle1").style.transform = "rotate(0deg)";
}

});
});
This code is right, FAQ icon didn’t rotating issue how to solve it