Created
October 16, 2018 23:13
-
-
Save emilio/e31d9771de9b40f878cf24cd92a19927 to your computer and use it in GitHub Desktop.
Move a frame without reloading it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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