window.opener
window.opener 实际上就是通过window.open打开的窗体的父窗体。
比如在父窗体parentForm里面 通过 window.open("subForm.html"),那么在subform.html中 window.opener
就代表parentForm,可以通过这种方式设置父窗体的值或者调用js方法。
如:1,window.opener.test(); ---调用父窗体中的test()方法
2,如果window.opener存在,设置parentForm中stockBox的值。
if (window.opener && !window.opener.closed) {
window.opener.document.parentForm.stockBox.value = symbol;
}
1>window.opener 的用法
在一般的用法中,只是用来解决关闭窗口时不提示弹出窗口, 而对它更深层的了解一般比较少。其 实 window.opener是指调用window.open方法的窗口。 在工作中主要是用来解决部分提交的。这种跨页操作对工作是非常有帮助的。 如果你在主窗口打开了一个页面,并且希望主窗口刷新就用这个,打开页面的window.opener就相当于 主窗口的window。
主窗口的刷新你可以用 window.opener.location.reload(); 如果你用虚拟的目录:如struts的*.do会提示你重试
你可以改成这样 window.opener.yourformname.submit() 就好了
2〉
在应用中有这样一个情况, 在A窗口中打开B窗口,在B窗口中操作完以后关闭B窗口,同时自动刷新A窗口
function closeWin(){
hasClosed = true;
window.opener.location="javascript:reloadPage();";
window.close(); }
function window.onbeforeunload(){
if(!hasClosed){
window.opener.location="javascript:reloadPage();";
}
}
上面的代码在关闭B窗口的时候会提示错误,说缺少Object,正确的代码如下:
function closeWin(){
hasClosed = true;
window.opener.location="javascript:reloadPage();";
window.opener=null;
window.close();
}
function window.onbeforeunload(){
if(!hasClosed){//如果已经执行了closeWin方法,则不执行本方法
window.opener.location="javascript:reloadPage();";
}
}
reloadPage方法如下:
function reloadPage() {
history.go(0);
document.execCommand("refresh")
document.location = document.location;
document.location.reload(); }
PS:由于需要支持正常关闭和强制关闭窗口时能捕捉到事件,用了全局变量hasClosed
==============================================
补充,在父窗口是frame的时候在刷新父窗口的时候会出现问题:
The page cannot be refreshed without resending the information. 后修改如下: window.opener.parent.document.frames.item('mainFrame').location.href = window.opener.location.href; 不需要执行自带的reload()方法,注意,不要再画蛇添足加上这一句:
window.opener.parent.document.frames.item('mainFrame').location.reload();
======================================================================================== 最后,为了同时支持刷新普通父窗口和frame父窗口,代码如下:
function closeWin() {
hasClosed = true;
}
window.opener的更多相关文章
- js jquery 关闭弹出页面 并刷新父页面(window.opener)
function Closepage() { if (window.opener && !window.opener.closed) { window.parent.opener.lo ...
- window.parent 与 window.opener
window.parent针对iframe,window.opener针对window.open 父页面parent.jsp: <%@ page language="java" ...
- window.opener强大功能
window.opener后面的方法可以调用任意父窗口里面js的方法. eg.query()是父窗口的 function refreshParent(){ window.opener.query( ...
- [转]window.opener用法
window.opener 实际上就是通过window.open打开的窗体的父窗体. 比如在父窗体parentForm里面 通过 window.open("subForm.html" ...
- JavaScript中,window.opener是什么?window.parent和window.opener有啥区别?
来自CSDN的问答: window.opener是什么啊? ++++++++++++++++++++++++++++++++++++++++++++++++++ 弹出本窗体的句柄 比如你想点一个按钮直 ...
- window.opener调用父窗体方法的用法
应用实例: function BindWindowCloss() { $(window).bind('beforeunload', function () { ...
- window.opener用法
[转]window.opener用法 window.opener 实际上就是通过window.open打开的窗体的父窗体. 比如在父窗体parentForm里面 通过 window.open(&quo ...
- JQuery window.opener
$('#Save').click(function () { var parent = $(parent.document.body); $(parent).find('input#add ...
- 关于Extjs使用window.opener报错
项目中使用window.opener 刷新父窗口表格,父窗口表格IE8报错, window.opener.Ext.getCmp('SalesCompanyGridPanel').getStore(). ...
- window.opener方法的使用 js跨域
原文:window.opener方法的使用 js跨域 最近公司网站登陆加入了第三方登陆.可以用QQ直接登陆到我们网站,在login页面A中点QQ登陆时,调用了一个window.open文件打开一个lo ...
随机推荐
- callee返回正被执行的Function对象
arguments.length是实参长度, arguments.callee.length是形参长度. function fn(a, b, c, d) { console.log(arguments ...
- ubuntu 配置虚拟主机
ubuntu下Apache虚拟主机的配置 启用站点停用站点方法 a2ensite/a2dissite 比如添加一个ecshop 的虚拟机 首先到/etc/apache2/site-availa ...
- Javascript&Html-history对象
Javascript&Html-history对象 history对象保存着用户的上网记录,这些记录从用户打开浏览器开始. 用户借助history对象实现的跳转. history.go(-1) ...
- selenium题
一.selenium中如何判断元素是否存在? 首先selenium里面是没有这个方法的,判断元素存在需要自己写一个方法了. 元素存在有几种形式,一种是页面有多个元素属性重复的,这种直接操作会报错的:还 ...
- 启动tomcat服务器自动执行一个方法
第一步:配置web.xml文件 添加如下代码 <servlet> <servlet-name>Timer</servlet-name> <servlet-cl ...
- html table 使用总结
html中的table是一个历史相当悠久的标签,它能够很方便的实现数据的表格展示.虽然table是个很基础的标签,但是想用好还是对css相关知识有要求的. 由于table标签中自带的属性操作起来略为麻 ...
- (7)python tkinter-菜单栏
菜单栏 Menu f = tkinter.Menu(root) root['menu']=f f.add_command(label='菜单')# f.add_command(label='关于') ...
- IOS7开发~错误收集
1. fatal error: file '/Applications/Xcode5-DP.app/Contents/Developer/Platforms/iPhoneSimulator.platf ...
- Mapxtreme 在64位系统运行网站,提示未能加载文件或程序集,或它的某一个依赖项
在32位系统上开发的网站,现在需要布署到64位系统上运行,布署好后访问提示提示未能加载文件或程序集,或它的某一个依赖项.在网上搜索后,发现是64位下引用dll出现的这个问题.这个问题通常出在引用第三方 ...
- 关于IIS的IUSER和IWAM帐户
IUSER是Internet 来宾帐户匿名访问 Internet 信息服务的内置帐户 IWAM是启动 IIS 进程帐户用于启动进程外的应用程序的 Internet 信息服务的内置帐户 (在白吃点就是启 ...