Last active
March 16, 2023 03:39
-
-
Save Risyandi/2d7a5bc1877c2dd3b8a927ef0e2d7093 to your computer and use it in GitHub Desktop.
how to create page with contain iframe full page responsive and access others website in nuxtjs
This file contains hidden or 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
<template> | |
<div class="iframe-container"> | |
<iframe | |
class="iframe" | |
:src="iframeUrl" | |
allowfullscreen | |
scrolling="yes" | |
ref="iframe" | |
@load="handleIframeLoad" | |
></iframe> | |
</div> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
iframeUrl: 'https://www.example.com', // set your own URL here | |
}; | |
}, | |
methods: { | |
handleIframeLoad() { | |
// Adjust the height of the iframe to match its content | |
const iframe = this.$refs.iframe; | |
const body = iframe.contentWindow.document.body; | |
const html = iframe.contentWindow.document.documentElement; | |
const height = Math.max( | |
body.scrollHeight, | |
body.offsetHeight, | |
html.clientHeight, | |
html.scrollHeight, | |
html.offsetHeight | |
); | |
iframe.style.height = `${height}px`; | |
}, | |
}, | |
}; | |
</script> | |
<style> | |
.iframe-container { | |
position: relative; | |
overflow: hidden; | |
width: 100%; | |
padding-top: 56.25%; /* 16:9 aspect ratio */ | |
} | |
.iframe { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
border: none; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment