The World's First Contextual Real-Time Quiz

Learn More

Embed

Home / Embed
TriviaTrap.ai

Embed TriviaTrap.AI on Your Website

Copy and Paste the code below into the body of your site where you want the quiz to appear. For best results place the quiz Above the Fold.
To embed an iframe with the current page title as the subject of the quiz, use the following code:

<script>
     document.addEventListener('DOMContentLoaded', function() {
        function getParentTitle() {
            return encodeURIComponent(document.title);
        }

        function getParentDomain() {
            return encodeURIComponent(window.location.hostname);
        }

        // Get all iframe elements with the class "iframe-class"
        let iframes = document.getElementsByClassName('iframe-class');
        let title = getParentTitle();
        let domain = getParentDomain();

        for (let i = 0; i < iframes.length; i++) {
            iframes[i].src = "https://triviatrap.ai/store-mcqs?content=" + title + "&domain=" + domain;
        }
    });
</script>
<iframe class="iframe-class" style=" width: 300px; height:250px;"></iframe>
<script>
    const iframes = document.getElementsByClassName('iframe-class');

    Array.from(iframes).forEach((iframe) => {
        iframe.onload = function() {
            try {
                // Attempt to get the content height
                let contentHeight = iframe.contentWindow.document.body.scrollHeight;
                contentHeight = contentHeight + 30;
                iframe.style.height = contentHeight + 'px';
            } catch (error) {
                iframe.style.height = '250px';
            }
        };
    });
</script>
`
shape-1

Embed TriviaTrap.AI using custom tags


`

Embed TriviaTrap.AI using dynamic meta tags