Skip to content

Instantly share code, notes, and snippets.

@emilio
Created October 16, 2018 23:13
Show Gist options
  • Save emilio/e31d9771de9b40f878cf24cd92a19927 to your computer and use it in GitHub Desktop.
Save emilio/e31d9771de9b40f878cf24cd92a19927 to your computer and use it in GitHub Desktop.
Move a frame without reloading it.
<!doctype html>
<div id="host" style="overflow: hidden">
<iframe slot="first" src="https://example.com" id="theframe"></iframe>
</div>
<button onclick="theframe.setAttribute('slot', theframe.getAttribute('slot') == 'first' ? 'second' : 'first')">
Click to move the frame around, hopefully without reloading.
</button>
<script>
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
div {
width: 50%;
border: 2px solid;
float: left;
}
#first { background: blue }
#second { background: purple }
</style>
<div id="first">
<slot name="first">Fallback 1</slot>
</div>
<div id="second">
<slot name="second">Fallback 2</slot>
</div>
`;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment