I simply need to be able to add a script that can interact with other elements on the page. It is a call tracking script that will replace all instances of a phone number dynamically with a unique call tracking number.
The HTML component will not work, as this gets wrapped in an iframe, and thus can’t interact with the rest of the site.
How can I add a third-party script so that it appears within the same document as the rest of the code, not within a nested document?
WixCode understands all of Javascript, except for anything that accesses the DOM. Therefore, WixCode does not allow interaction with elements on the page.
This keeps the user from inadvertently “breaking” something. I myself tried to hack things from the code, from an iFrame, and in my dreams, but WixCode wasn’t having any of it.
Accessing document elements such as div, span, button, etc is off-limits. The way to access elements on the page is only through $w.
You won’t be able to access the elements. Since you have access to the data that populates these elements, you could manipulate the data, and then assign these modified values to the appropriate elements.
The HTML code for your 3rd party app could be in an HtmlComponent, and the HtmlComponent can then send a message to the page with the relevant information needed to modify the data.
I have a feeeling that that’s not really what you’re looking for, but you might be able to cobble something together and somehow get the same result.
@yisrael-wix is there an example somewhere showing how to do your latest recommendation? I don’t need to access the DOM. I’m looking for a way to use third party js to tokenize sensitive data before sending it to the backend… Is using an HTMLComponent a way to do that?