iframe

iframe中跨域页面访问parent的方法

那年仲夏 提交于 2020-02-26 09:38:37
iframe中跨域页面访问parent的方法 : 跨域实例: 如上图所示,系统www.a.com/index.html页面中嵌入一个iframe,iframe中访问不同域的www.b.com/index.html 然后b中有个按钮“保存”,想调用父页面a.com/index.html中的一个js方法saveFavorite() 问题: iframe和父页面如果是同一个域的,那问题很好办,直接parent.saveFavorite()即可。 但问题难在是不同域,不同域是不允许相互访问js代码的。 解决方案: 跨域的问题,也有不少的解决方案(参考: http://blog.csdn.net/sfdev/archive/2009/02/13/3887006.aspx ),这里提供一种比较优雅的方案。 解决方案说明如下: 在AAA.com域名下的index.htm页面中内嵌了BBB.com域名下的一个页面index.htm,正常情况下iframe内部的index.htm页面是无法访问父页面index.htm中的任何dom对象或者js函数的,因为跨域,但我们经常又需要做一些参数回传的事情怎么办呢?以上的这种实现方式就很好的解决了这个问题; 解决方案的关键优雅之处在于:浏览器虽然会禁止js跨域访问页面中的对象,但对于iframe的层级关系引用并没有做限制,即parent仍然可用

通过jQuery.Ajax下载文件

别来无恙 提交于 2020-02-26 06:29:25
我在服务器端有一个Struts2操作,用于文件下载。 <action name="download" class="com.xxx.DownAction"> <result name="success" type="stream"> <param name="contentType">text/plain</param> <param name="inputName">imageStream</param> <param name="contentDisposition">attachment;filename={fileName}</param> <param name="bufferSize">1024</param> </result> </action> 但是,当我使用jQuery调用操作时: $.post( "/download.action",{ para1:value1, para2:value2 .... },function(data){ console.info(data); } ); 在Firebug中,我看到数据是通过 Binary流 检索的。 我想知道如何打开 文件下载窗口 ,以便用户可以在本地保存文件吗? #1楼 1.与框架无关:Servlet下载文件作为附件 <!-- with JS --> <a href="javascript:window

Override CSS in an iframe

喜你入骨 提交于 2020-02-26 04:15:29
问题 On this page, the form is an iframe provided by JotForm. I want to left-align the form, and reduce the padding around the LI elements that contain the text fields. In Magento Go (the website platform hosting the website), I have entered the following code into custom.css: iframe#40142457787864 form#40142457787864 .form-all {margin: 0 !important;} iframe#40142457787864 form#40142457787864 .form-line {padding: 4px 0 !important;} However, this is not being applied by the browser. Why not? 回答1:

根据内容调整iframe的大小

点点圈 提交于 2020-02-26 03:25:32
我正在开发类似iGoogle的应用程序。 使用iframe显示其他应用程序(在其他域上)的内容。 如何调整iframe的大小以适合iframe内容的高度? 我试图破译Google使用的javascript,但是它被混淆了,到目前为止,在网络上搜索毫无结果。 更新: 请注意,内容是从其他域加载的,因此适用 同源策略 。 #1楼 使用jQuery的最简单方法: $("iframe") .attr({"scrolling": "no", "src":"http://www.someotherlink.com/"}) .load(function() { $(this).css("height", $(this).contents().height() + "px"); }); #2楼 这是一种通过iframe的src属性在json中添加信息的jQuery方法。 这是一个演示,调整大小并滚动此窗口。.带有json的结果url看起来像这样... http://fiddle.jshell.net/zippyskippy/RJN3G/show/#{docHeight:5124,windowHeight:1019,scrollHeight: 571}# 这是小提琴的源代码 http://jsfiddle.net/zippyskippy/RJN3G/ function updateLocation(

Jquery取得iframe中元素的几种方法

a 夏天 提交于 2020-02-26 00:55:42
在iframe子页面获取父页面元素 代码如下: $('#objId', parent.document); // 搞定... 在父页面 获取iframe子页面的元素 代码如下: $("#objid",document.frames('iframename').document) $(document.getElementById('iframeId').contentWindow.document.body).html() 显示iframe中body元素的内容。 $("#testId", document.frames("iframename").document).html(); 根据iframename取得其中ID为"testId"元素 $(window.frames["iframeName"].document).find("#testId").html() 用JS或jQuery访问页面内的iframe ,兼容IE/FF 注意:框架内的页面是不能跨域的! 假设有两个页面,在相同域下. index.html 文件内含有一个iframe: XML/HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1

JS操作iframe

跟風遠走 提交于 2020-02-26 00:49:03
1. 获得iframe的window对象 存在跨域访问限制。 chrome:iframeElement. contentWindow firefox: iframeElement.contentWindow ie6:iframeElement.contentWindow 文章 Iframes, onload, and document.domain 中 说“he iframe element object has a property called contentDocument that contains the iframe’s document object, so you can use the parentWindow property to retrieve the window object.”意思就是一些浏览器可以通过iframeElement.contentDocument.parentWindow获得iframe的 window对象。但经过测试firefox、chrome的element.contentDocument对象没有parentWindow属性。 function getIframeWindow(element){ return element.contentWindow; //return element.contentWindow ||

js获取iframe中的元素以及在iframe中获取父级的元素(包括iframe中不存在name和id的情况)

a 夏天 提交于 2020-02-26 00:26:24
第一种情况:iframe中不存在name和id的方法:(通过contentWindow获取) var iframe = document.getElementsByTagName('iframe')[0]; var ifr_document = iframe.contentWindow.document;//iframe中的文档内容 或者: var _iframe = document.getElementByIdx_x('iframeId').contentWindow; var _div =_iframe.document.getElementByIdx_x('objId'); 或者: var frameWin= document.getElementById('iframe').contentWindow; //window对象 var frameDoc= document.getElementById('iframeId').contentWindow.document //document对象 var frameBody= document.getElementById('iframeId').contentWindow.document.body //body对 第二种情况:iframe中存在name或者id的方法:(通过frames[]数组获取) document

ifarme获取父级元素

孤街浪徒 提交于 2020-02-26 00:26:02
js写法 a、同过contentWindow获取 也有用contentDocument 获取的 但是contentWindow 兼容各个浏览器,可取得子窗口的 window 对象。 contentDocument Firefox 支持,> ie8 的ie支持。可取得子窗口的 document 对象。 获取方法 [html] view plain copy print ? var frameWin= document.getElementById('iframe').contentWindow; //window对象 var frameDoc= document.getElementById('iframeId').contentWindow.document //document对象 var frameBody= document.getElementById('iframeId').contentWindow.document.body //body对象 b、通过frames[]数组获取 (但是必须在ifram框架加载完毕后获取,iframe1是iframe的name属性) [html] view plain copy print ? document.getElementById('iframId') .onload= function(){ var html= window

iframe的用法

两盒软妹~` 提交于 2020-02-26 00:25:39
有人说,iframe是能耗最高的一个元素,尽量减少使用。 也有人说,iframe的安全性太差,尽量减少使用。      虽然他们说的是真的,但是iframe的强大功能是不容忽视的,而且现在不乏公司正在使用它。   <iframe> 标签规定一个内联框架。一个内联框架被用来在当前 HTML 文档中嵌入另一个文档。   所有的主流浏览器都支持<iframe>标签。你可以把提示的文字放到 <iframe> 和 </iframe>里面,这样不支持 <iframe>的浏览器就会出现提示的文字。 iframe 如何使用呢? 通常我们使用iframe直接在页面嵌套iframe标签指定的src就可以了。 比如: <!-- <iframe> 标签规定一个内联框架     这里写p 标签是为了看align的效果 --> <p style="overflow: hidden;">这是一些文本。 这是一些文本。 这是一些文本。这是一些文本。 这是一些文本。 这是一些文本。 <iframe name="myiframe" id="myrame" src="external_file.html" frameborder="0" align="left" width="200" height="200" scrolling="no"> <p>你的浏览器不支持iframe标签</p> </iframe>

iframe详细的使用

自作多情 提交于 2020-02-26 00:25:12
谷歌火狐和ie是有区别的 谷歌需要服务器,为了更安全 获取内容的时候, 正常渲染没问题 获取内容 var oIframe = document.getElementById('iframe'); oIframe.contentWindow 获取到所有的内容节点 注:谷歌下会报错 需要服务器下 oIframe.contentWindow.document.getElementById('div') 获取到页面下的某个id为div的元素 oIframe.contentWindow.document.getElementById('div').style.color='red' 改变他的字体颜色 所有浏览器都支持 操控document oIframe.contentDocument.getElementById('div') 可以直接获取到document下的元素 注:ie6,7 不支持 。 所以在ie6,7 下需要获取window再操纵Document 另一种情况 就是 三成嵌套 利用最里面的iframe 控制最外层的父级 window.top 例如: iframe.html <body> <iframe src="iframe1.html"></iframe> </body> iframe3.html <body> aa <iframe src="iframe.html"><