| layout | page |
|---|---|
| title | About |
| permalink | /about/ |
This blog is my original work, archived in the _posts folder, and all rights are reserved.
Please contact me for authorization before reusing or reposting.
If you find this blog is useful, a simple star (Star on Github) should be the best affirmation. 😊
<style> /* 内联样式隔离 */ #iframe-wrapper { width: 100%; overflow: hidden; border: none; display: block; margin: 0; padding: 0; } #iframe-content { width: 100%; border: none; display: block; /* 消除 iframe 默认的 inline 空隙 */ } </style>
<iframe
id="iframe-content"
src="https://gohanwithchann.github.io/index.html"
onload="this.style.height = this.contentWindow.document.documentElement.scrollHeight + 'px'"
></iframe>
<script>
// 纯当前页面运行的脚本
document.getElementById('iframe-content').addEventListener('load', function() {
try {
const contentHeight = this.contentWindow.document.documentElement.scrollHeight;
this.style.height = contentHeight +100+ 'px';//增加了高度
// 添加窗口变化监听
window.addEventListener('resize', () => {
this.style.height = this.contentWindow.document.documentElement.scrollHeight + 'px';
});
} catch (error) {
console.log('跨域保护机制触发,请确保被嵌入页面与本站同源');
}
});
</script>