Skip to content

Instantly share code, notes, and snippets.

@ochafik
Last active August 6, 2021 21:37
Show Gist options
  • Save ochafik/ab740b275298928a3c44118c3a4c130a to your computer and use it in GitHub Desktop.
Save ochafik/ab740b275298928a3c44118c3a4c130a to your computer and use it in GitHub Desktop.
Static page that displays URL #hash content safely. Ideal to display payloads of QR codes.
<body style="margin: 0; padding: 0; overflow: hidden">
<iframe
id="content_frame"
frameborder="0"
style="overflow: hidden; height: 100%; width: 100%"
height="100%"
width="100%"
sandbox="allow-scripts">
</iframe>
<script>
const contentFrame = document.getElementById('content_frame');
const baseUrl = location.href.split('#')[0];
const hash = location.hash || window.name;
if (hash.startsWith('#')) {
const content = decodeURIComponent(hash.substring(1));
if (content.startsWith('data:')) {
contentFrame.src = content;
} else {
contentFrame.srcdoc = content;
}
history.replaceState(null, '', baseUrl);
window.name = hash;
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment