Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Last active March 16, 2023 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risyandi/2d7a5bc1877c2dd3b8a927ef0e2d7093 to your computer and use it in GitHub Desktop.
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
<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