JS实现子窗口传值到父窗口
2016-07-01 15:33
721 查看
以前很少用JS,通过这次学习MVC碰到不少问题,比如子窗口要传值给父窗口。
方法大致有两种,此处说当前使用的这种方法:
父窗口打开子窗口时,使用window.open方式打开,以下摘抄了两个使得子窗口居中的JS方法,第一个是子窗口屏幕居中,第二个是在上级页面中居中
1>
/*打开网页 window.open
/*url: 表示请求路径
/*windowname: 定义页名称
/*width: 宽度
/*height: 高度
---------------------------------------------------*/
function OpenWindowByScreen(url, title, w, h) {
var iWidth = w;
var iHeight = h;
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(RootPath() + url, title, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, titlebar=yes,
alwaysRaised=yes');
}
2>
/*打开网页 window.open
/*url: 表示请求路径
/*windowname: 定义页名称
/*width: 宽度
/*height: 高度
---------------------------------------------------*/
function OpenWindow(url, title, w, h) {
var width = w;
var height = h;
var left = ($(window).width() - width) / 2;
var top = ($(window).height() - height) / 2;
window.open(RootPath() + url, title, 'height=' + height + ', width=' + width + ', top=' + top + ', left=' + left + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, titlebar=yes, alwaysRaised=yes');
}
————————————————————————————————————————————————————————
子窗口传值给父窗口时:
window.opener.document.getElementById("Downloads").value += '新值';
此处的Downloads即为父窗口中的一个textarea元素
要求父窗口打开子窗口时须使用window.open方法才能使用window.opener回传值
方法大致有两种,此处说当前使用的这种方法:
父窗口打开子窗口时,使用window.open方式打开,以下摘抄了两个使得子窗口居中的JS方法,第一个是子窗口屏幕居中,第二个是在上级页面中居中
1>
/*打开网页 window.open
/*url: 表示请求路径
/*windowname: 定义页名称
/*width: 宽度
/*height: 高度
---------------------------------------------------*/
function OpenWindowByScreen(url, title, w, h) {
var iWidth = w;
var iHeight = h;
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(RootPath() + url, title, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, titlebar=yes,
alwaysRaised=yes');
}
2>
/*打开网页 window.open
/*url: 表示请求路径
/*windowname: 定义页名称
/*width: 宽度
/*height: 高度
---------------------------------------------------*/
function OpenWindow(url, title, w, h) {
var width = w;
var height = h;
var left = ($(window).width() - width) / 2;
var top = ($(window).height() - height) / 2;
window.open(RootPath() + url, title, 'height=' + height + ', width=' + width + ', top=' + top + ', left=' + left + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, titlebar=yes, alwaysRaised=yes');
}
————————————————————————————————————————————————————————
子窗口传值给父窗口时:
window.opener.document.getElementById("Downloads").value += '新值';
此处的Downloads即为父窗口中的一个textarea元素
要求父窗口打开子窗口时须使用window.open方法才能使用window.opener回传值
相关文章推荐
- js Array数组的使用
- Extjs--checkbox,选中与不选中
- listview滚动到底部可以继续加载,结合json解析
- 使用 JS 复制文本内容
- 说说JSON和JSONP,也许你会豁然开朗
- Js 操控 Cookie(简单实用)
- 文件上传的渐进式增强
- javascript学习资源
- ajaxfileupload回到json带<pre>
- json字符串转json对象
- js frameset 父子页面互动
- js去空格
- 一段JS 分时显示 欢迎信息
- js实现刮刮卡效果
- JS怎样捕获浏览器关闭时间弹出自定义对话框
- JavaScript中获得指定日期字符串问题
- JavaScript中继承方式详解
- js简单的弹出框有关闭按钮
- ArcGIS Engine中 IGeometry和Json字符串的相互转换
- C# 生成Json数据