概述

本地同一浏览器访问本地HTML文件和访问服务器端HTML文件,本地Iframe没有自适应高度,而服务器端的Ifrane自适应了高度。

1.问题重现:

Chrome 版本 41.0.2272.101 (64-bit)

OS:Win8.1

Chrome访问服务器端HTML文件呈现的结果

Chrome访问本地HTML文件呈现的结果

本地访问的HTML文件Iframe没有根据Iframe里面的页面类容自适应高度

2.Iframe自适应高度代码

在index.html文件中间中添加Iframe页面,页面加载时,加载src指定的文件路径

<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高度

    </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>

3.调试代码

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协议不熟悉,请大家不吝赐教。

【HTML】iframe跨域访问问题的更多相关文章

  1. iframe跨域访问

    js跨域是个讨论很多的话题.iframe跨域访问也被研究的很透了. 一般分两种情况: 一. 是同主域下面,不同子域之间的跨域: 同主域,不同子域跨域,设置相同的document.domian就可以解决 ...

  2. CP="CAO PSA OUR" 用P3P header解决iframe跨域访问cookie

    1.IE浏览器iframe跨域丢失Session问题 在开发中,我们经常会遇到使用Frame来工作,而且有时是为了跟其他网站集成,应用到多域的情况下,而Iframe是不能保存Session的因此,网上 ...

  3. 在IE浏览器中iframe跨域访问cookie/session丢失的解决办法

    单点登录需要在需要进入的子系统B中添加一个类,用于接收A系统传过来的参数: @Action(value = "outerLogin", results = { @Result(na ...

  4. js iframe跨域访问

    1.什么是跨域? 2.前台解决跨域几种方法 2.1 动态创建script 2.2 使用document.domain 2.3使用HTML5新属性postMessage 2.4 利用iframe和loc ...

  5. IFrame跨域访问自定义高度

    由于JS禁止跨域访问,如何实现不同域的子页面将高度返回给父页面本身,是解决自定义高度的难点. JS跨域访问问题描述:应用A访问应用B的资源,由于A,B应用分别部署在不同应用服务器(tomcat)上,属 ...

  6. IFrame跨域访问&&IFrame跨域访问自定义高度

    1.IFrame跨域访问: http://blog.csdn.net/fdipzone/article/details/17619673 2.IFrame跨域访问自定义高度: 由于JS禁止跨域访问,如 ...

  7. javascript跨域、iframe跨域访问

    1.window 对象 浏览器会在其打开一个 HTML 文档时创建一个对应的 window 对象.但是,如果一个文档定义了一个或多个框架(即,包含一个或多个 frame 或 iframe 标签),浏览 ...

  8. iframe跨域访问出现的cookie问题,提供两种解决方案

    最近在java项目对接时出现的一个问题.A系统嵌入B系统页面时,使用iframe去嵌入B系统页面丢失sessionid,导致B系统认为是未进行登录的请求,从而跳转到了B系统登录页. 解决方法查看此博客 ...

  9. IE中iframe跨域访问

    http://blog.csdn.net/ghsau/article/details/13747943

随机推荐

  1. Quartz 框架的应用

    本文将简单介绍在没有 Spring 的时候..如何来使用 Quartz... 这里跳过 Quartz 的其他介绍.如果想更加输入的了解 Quartz,大家可以点击下载Quartz的帮助文档. Quar ...

  2. js/jq宽高的理解与运用

    document:1. 与client相关的宽高document.body.clientWidthdocument.body.clientHeightdocument.body.clientLeftd ...

  3. Android JNI HelloWorld实现

    创建一个JNIDemo的Android工程 在项目下创建一个文件夹jni.(注意必须是jni目录) 在jni目录下创建两个文件:Android.mk 和 first_jni.c(.c文件的名字可以任意 ...

  4. 网页二维码推广App的实现

    移动互联网时代,一个APP的平均推广成本早已经超过了10块.而推广通常分二类: 1.已经下载过的用户,可以直接打开应用(一般人的手机上安装的应用都非常多,要快速找到某个应用是很困难的事情,而且Andr ...

  5. Distributed Result Grouping Caveats

    Distributed Result Grouping Caveats Grouping is supported distributed searches, with some caveats: 1 ...

  6. 工作组环境下管理windows.

    此处指的是windows7 1.防火墙设置 开启wmi,remote admin,防火墙远程管理 可以使用命令行 netsh advfirewall export "C:\temp\WFco ...

  7. webService发布和调用--Axis2

    一.工具 1.下载 Axis2以及eclipse的Axis2插件.http://axis.apache.org/axis2/java/core/download.cgi 2.axis2-1.7.1-w ...

  8. SK-Learn使用NMF(非负矩阵分解)和LDA(隐含狄利克雷分布)进行话题抽取

    英文链接:http://scikit-learn.org/stable/auto_examples/applications/topics_extraction_with_nmf_lda.html 这 ...

  9. mac上parallel与virtualbox无法共存

    Mac reboots when you attempt to launch Parallels Desktop 8 and Virtual Box simultaneously Article ID ...

  10. TokuDB调研文档

    另见链接:http://note.youdao.com/share/?id=77dd1e9cc139b57586665f702467c56a&type=note   安装 安装主要包括两种方法 ...