JSFiddle - React, Tailwind, and code Playground

by Chris

JavaScript

// Create a Trusted Types policy
const policy = trustedTypes.createPolicy('default', {
    createHTML: (input) => input
});

// Function to inject the iframe
function injectIframe() {
    const safeHtml = policy.createHTML(`
        <div id="custom-container" style="position:fixed; bottom:10px; right:10px; width:500px; height:300px; border:1px solid black;">
            <iframe src="https://example.com" width="100%" height="100%" style="border:none;"></iframe>
        </div>
    `);

    // Inject into the body without replacing existing content
    const container = document.createElement('div');
    container.innerHTML = safeHtml;
    document.body.appendChild(container.firstChild);
}

// Call the function to inject the iframe
injectIframe();