Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Last active August 8, 2024 10:01
Show Gist options
  • Save Luzifer/466839738ae6d2f0448ac59961e13a52 to your computer and use it in GitHub Desktop.
Save Luzifer/466839738ae6d2f0448ac59961e13a52 to your computer and use it in GitHub Desktop.
Confluence Datacenter user-macro to embed an iFrame including some extra features
## @param Height:title=Height|type=int|required=false|default=500|desc=Height of the embed
## @param Src:title=Source|type=string|required=true|desc=URL to embed
## @param AutoResize:title=Auto-Resize|type=boolean|required=false|default=false|desc=Enable Script to Auto-Resize frame
<iframe
id="confluenceFrame"
frameborder="0"
height="$paramHeight"
referrerpolicy="same-origin"
src="$paramSrc"
width="100%"
></iframe>
<script>
const frame = document.getElementById('confluenceFrame')
const html = document.getElementsByTagName('html')[0]
frame.addEventListener('load', () => {
frame.contentWindow
.postMessage({
confluenceColorMode: html.dataset.colorMode,
}, '$paramSrc')
})
#if ($paramAutoResize)
window.addEventListener('message', event => {
if (event.data.confluenceFrameHeight) {
frame.style.setProperty('height', `${event.data.confluenceFrameHeight}px`)
}
})
#end
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment