HTML iframe 內嵌網頁

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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章