CMS Code Injection ❺🧪
Inject custom code from the CMS anywhere in your Webflow page.
Goals
Prototype
<script>
// Step 1: Define your HTML-encoded content
const encodedContent = ` ADD YOUR CODE EMBED FIELD HERE `;
// Step 2: Decode the HTML-encoded content
function htmlDecode(input) {
const doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
const decodedContent = htmlDecode(encodedContent);
// Step 3: Create a temporary container
const tempContainer = document.createElement('div');
tempContainer.innerHTML = decodedContent;
const currentScript = document.currentScript;
// Step 4: Append the contents to the desired location
// For example, appending to the document body
while (tempContainer.firstChild) {
// document.body.appendChild(tempContainer.firstChild);
currentScript.parentNode.insertBefore(tempContainer.firstChild, currentScript);
}
// Step 5: Remove this injector script element
currentScript.parentNode.removeChild(currentScript);
</script>Last updated