HTML iframe 内嵌网页

    技术2022-07-16  61

    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>

     

    Processed: 0.024, SQL: 10