背景:项目用 easyUI 写前端,窗口使用 easyui-window 内嵌套 iframe 展示页面。遇到需要在窗口间传输数据的需求。

解决方案

获取 iframe 对象,然后通过获取的 iframe 对象操作该页面内的元素;

代码

// 示例
var iframe = GetIframe("iframe_dlgMyDialog");
var datagrigDatas = iframe.$("#dg").datagrid('getData'); // 获取iframe对象
function GetIframe(name) {
var browserType = myBrowser();
var iframe; // IE浏览器
if (browserType == "IE" || browserType == "IE10+") {
iframe = parent.window.frames[name];
}
else {
iframe = parent.window.frames[name].contentWindow;
} return iframe;
} // 判断当前浏览类型 
function myBrowser() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 
var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器 
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器 
var isEdge = userAgent.indexOf("Windows NT 6.1;") > -1 && userAgent.indexOf("Trident/7.0;") > -1 && !isIE; //判断是否IE的Edge浏览器 
var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器 
var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器 
var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1; //判断Chrome浏览器 if (isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if (fIEVersion == 7) { return "IE"; }
else if (fIEVersion == 8) { return "IE"; }
else if (fIEVersion == 9) { return "IE"; }
else if (fIEVersion == 10) { return "IE10+"; }
else if (fIEVersion == 11) { return "IE10+"; }
else { return "0" }//IE版本过低 
}
if (isFF) { return "FF"; }
if (isOpera) { return "Opera"; }
if (isSafari) { return "Safari"; }
if (isChrome) { return "Chrome"; }
if (isEdge) { return "IE10+"; }
}

跨 iframe 传输数据的更多相关文章

  1. Flash跨域传输数据 crossdomain.xml

    一.概述位于www.a.com域中的SWF文件要访问www.163.com的文件时,SWF首先会检查163服务器目录下是否有crossdomain.xml文件,如果没有,则访问不成功:若crossdo ...

  2. 解决cookie 跨iframe

    document.cookie = "name=caoyc;path=/"document.cookie = "age=13;path=/"//时间可以不要,但 ...

  3. window.postMessage 跨窗口,跨iframe javascript 通信

    同源通信 执行它们的页面位于具有相同的协议(http/https),端口(80/443),主机(通常为域名) 时,这两个脚本才能相互通信 大多数情况下,网站就是内部的域名,所以是同源通信,可以相互访问 ...

  4. $.post 跨域传输数据

    使用的是TP框架 前端代码: <!DOCTYPE html><html> <head> <title>这里是前端代码</title> < ...

  5. easyui跨iframe属性datagrid

    1.问题 如何刷新easyui父级tab页中iframe嵌套页中的datagrid? 2.解决方法 (1) parent.$("iframe[title='tabtitle']") ...

  6. [基础不过关填坑] 跨iframe触发事件

    子iframe $("#testId").on("change",function(){ alert("change") }) 父页面 $( ...

  7. 跨server传输数据注意事项

    我们需要模拟客服端 首先导入相关的jar包 文件,Jersey的相关jar包 实现客服端的代码为: @Test    public  void testClient() {        //图片生成 ...

  8. json和jsonp解决跨域传输数据等

    https://kb.cnblogs.com/page/139725/ https://blog.csdn.net/lambert310/article/details/51683775

  9. IE跨Iframe时Session丢失问题

    例如IIS下,可以打开IIS窗口——〉选择一个网站——〉属性——〉http头,增加一个http头 然后输入头名:P3P 输入头内容:CP=CAO PSA OUR 点评:与上一个方法类似,此方法也要求第 ...

随机推荐

  1. vue 设置button disabled

    <button v-bind:disabled="dis" @click="alert">button</button> dis:'' ...

  2. 编译https://github.com/CIR-KIT/steer_drive_ros时出现的问题

    解决gazebo对应的protobuf版本问题: I've come across to the same problem. I'm using Ubuntu 16.04, ROS Kinetic a ...

  3. mybatis学习六 parameterType 属性

    1. 在 XXXMapper.xml 中<select><delete>等标签的 parameterType 可以控制参数类型2. SqlSession 的 selectLis ...

  4. kbmmw 的HTTPSmartService 上传文件到服务器端

    前面我写过了 HTTPSmartService 使用介绍,可以参见以前的文章. 前一向有同学问如何在http 页面表单上上传文件.一直没有时间回答,自己简单做了例子, 发现无法实现功能,今天花了一天时 ...

  5. NOIP 2017 d2t2 70points

    革命之路漫漫 第一次尝试 40points spfa #include <bits/stdc++.h> #define read read() using namespace std; i ...

  6. 谈互联网开放平台:“去中心化”大势所趋 zz

    文/磐石之心 几天前与好友聊到众筹咖啡馆的事情,他向我讲述了一个非常具有特色的众筹咖啡馆案例.而这个案例也引发我对当前互联网开放.去中心和集权的一些思考,今天就简单写出来与大家分享. 一个无赚钱目的的 ...

  7. Win7 VS2013环境cuda_7.5.18的一些坑

    thrust库的sort算法,在x86平台使用就崩溃,x64就没问题,搜了下好像是很早的版本,4开始就有这样的问题了,原因不明. http://stackoverflow.com/questions/ ...

  8. Win7 VS2015环境编译NanoVG

    书接上回,Cairo编译好使用后,发现简单的每帧画100条随机线段就卡得不行,装了个gooreplacer( http://liujiacai.net/gooreplacer/ )上stackover ...

  9. c# radiobutton

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  10. 第28章:MongoDB-索引--过期索引(TTL)

    ①过期索引(TTL) TTL索引是让文档的某个日期时间满足条件的时候自动删除文档,这是一种特殊的索引,这种索引不是为了提高查询速度的,TTL索引类似于缓存,缓存时间到了就过期了,就要被删除了 ②范例: ...