Hi everyone,
I’m embedding a custom-built calculator in my site [ irregular area calculator] into different websites using a small JavaScript snippet.
The calculator works perfectly when:
-
Opened directly on my website
-
Tested locally
-
Embedded in a simple HTML file
However, when I try embedding it into certain platforms (Google Sites, WordPress blocks, or some CMS builders), I’m facing issues like:
-
The calculator container loads but JS doesn’t initialize
-
Event listeners don’t fire
-
Sometimes calculations work, but dynamic result sections don’t toggle
-
In a few cases, the script is silently blocked
Here’s a simplified version of my structure:
CalculateIn some environments, inline JS seems restricted or partially sandboxed.
I’ve also tried:
-
Moving JS to an external file
-
Using
DOMContentLoadedevent listeners -
Wrapping everything inside an IIFE
-
Removing inline
onclickand usingaddEventListener
Still inconsistent results depending on where it’s embedded.
My questions:
-
Are certain platforms blocking inline scripts by default?
-
Is there a more embed-friendly approach I should be using? (iframe? modular loader?)
-
Should I convert the calculator to a fully self-contained JS widget?
-
Are there best practices for distributing embeddable calculators?
I’d appreciate guidance from anyone experienced with cross-platform JS embeds.
Thanks in advance!