本地同一瀏覽器訪問本地HTML文件和訪問服務器端HTML文件,本地Iframe沒有自適應高度,而服務器端的Ifrane自適應了高度。javascript
Chrome 版本 41.0.2272.101 (64-bit)html
OS:Win8.1java
Chrome訪問服務器端HTML文件呈現的結果跨域
Chrome訪問本地HTML文件呈現的結果瀏覽器
本地訪問的HTML文件Iframe沒有根據Iframe裏面的頁面類容自適應高度服務器
在index.html文件中間中添加Iframe頁面,頁面加載時,加載src指定的文件路徑dom
<iframe id="indexFrame" name="index" width="800" onload='iFrameHeight("indexFrame")' src="Web/Index/indexIframe.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
JS腳本自適應調整Iframe高度spa
</script> <script type="text/javascript" language="javascript"> function iFrameHeight(id) { var ifm = document.getElementById(id); var subWeb = document.frames ? document.frames[id].document : ifm.contentDocument; if (ifm != null && subWeb != null) { ifm.height = subWeb.body.scrollHeight; } } </script>
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.調試
在這裏,我猜想是訪問本地文件是file協議(file:///),HTML代碼和JS代碼存在跨域問題。小弟對file協議不熟悉,請你們不吝賜教。code