Gray Wolf Corporation

Suppress gist footer to prevent X-Origin errors from iframe links in component

The last item to be ported from my old site was a component for displaying gists.

I found this solution at stackoverflow and modified for Blazor Server and MudBlazor.

Everything was working great in the component until I clicked on the default footer links at the bottom of the gist. This would try to load the gist url within the iframe, rather than open a new tab, which resulted in some sort of X-Origin header conflict and "unable to connect' errors.

The simplest fix was to provide a gihub link outside of the iframe and hide the gist-meta div. Other solutions added an onclick event to all the "a" elements in the iframe, but this seems simpler.

    const styleScript = '<style>.gist .gist-meta { display: none !important; }</style>';    
    const gistScript = `<script src="https://gist.github.com/${userId}/${filename}.js"></script>`;
    const resizeScript = `onload="parent.document.getElementById('${iframeId}').style.height=document.body.scrollHeight + 'px'"`;
    const iframeHtml = `<html><head>${styleScript}</head><body ${resizeScript}>${gistScript}</body></html>`;
Suppress gist footer to prevent X-Origin errors from iframe links in component
An unhandled error has occurred. Reload 🗙