1. HTML
<iframe src="https://cn.bing.com/" width="100%" height="500px">
</iframe>
2. 請求URL顯示錯誤: Refused to display 'http://127.0.0.1:8000/show/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
X-Frame-Options:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/X-Frame-Options
Django中的X-Frame-Options設置:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/X-Frame-Options
3. 設置iframe的高度根據網頁的高度變化
<script type="application/javascript">
function resizeIFrameToFitContent( iFrame ) {
// iFrame.width = document.body.scrollWidth;
iFrame.height = window.screen.height - 300;
}
window.addEventListener('DOMContentLoaded', function(e) {
// var iFrame = document.getElementsByTagName( 'iframe' );
// resizeIFrameToFitContent( iFrame );
// or, to resize all iframes:
var iframes = document.querySelectorAll("iframe");
for( var i = 0; i < iframes.length; i++) {
resizeIFrameToFitContent( iframes[i] );
}
} );
</script>