`

window.opener.location.reload() and href的区别

阅读更多

      2个方法都是刷新父窗口,但是其中还是有奥妙的哦。


      window.opener.location.reload();这个方法在强迫父窗口的时候,在有些IE浏览器(比如安全设置高)的情况下,会弹出一个确认对话框,提示是不是要重新再刷新一次页面,这可是比较郁闷的事情哦,我后来把这个方法替换成了window.opener.location.href=window.opener.location.href;
就不会出现那样的问题了。

 

       window.opener其实是指本窗口的父窗口,比如,one.jsp 通过popupwindow打开了two.jsp,哪么在two.jsp里面的window.opener就是指one.jsp,所以在two.jsp里面完全可以用window.opener调用任何一个one.jsp里面的方法,实现one.jsp和two.jsp的交互。

 

       注意:window.opener.location.href只是一个链接,如果想实现父窗口的提交就要调用window.opener.action="" 和window.opener.submit();方法,但是不幸的是这段代码在firefox下不能运行,解决的办法为在父窗口中写一个提交的function在子窗口中通过window.opener.functionname()调用。

 

       通常在使用window.opener的时候要去判断父窗口的状态,如果父窗口被关闭或者更新,就会出错,解决办法是加上如下的验证if(window.opener && !window.opener.closed)

分享到:
评论

相关推荐

    jsp 刷新父页面

    window.opener.location.href = window.opener.location.href 刷新以winodw.showModelDialog()方法打开的窗口 window.parent.dialogArguments.document.execCommand('Refresh'); 或 Response.Write("<script>...

    [removed].reload 刷新使用分析(去对话框)

    使用[removed].reload;...window.opener.location.href=window.opener.location.href; window.opener.location.reload(); 这种写法就不出现那讨厌的对话框啦! 介绍JS实现刷新iframe的方法 <iframe src=”1.ht

    关闭时刷新父窗口两种方法

    window.opener.location.reload()刷新父窗口window.opener.location.reload() 与 window.opener.location.href=window.opener.location.href 都是弹出窗口关闭时用来刷新父窗口。 但[removed].Reload 如果有数据提交...

    JS刷新父页面 父窗口

    // 刷新父页面。此段代码放在被弹出的页面 function refreshOpener() { ... if (win.opener) win.opener.location.reload();//或parent.location.reload(); } catch (ex) { } } ......................

    window.open的页面如何刷新(父页面)上层页面

    代码如下: this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, “window.opener.location.reload();alert(‘销帐成功!’);”, true); 主要是这段js代码:window.opener.location.reload...

    JS窗口大全----很全的哦

    //-----------按钮提示框----------// ...window.opener.location.reload();window.close()">返回</a> javaScript:window.location.reload();//返回当前页并刷新 。。。。。。。。。。。。。。。。。。。。

    子窗体与父窗体传值示例js代码

    //获取父页面 //parent.location.reload(); //刷新父页面 if (parent != null && parent != “undefined”) { window.returnValue = value; //返回值 window.close(); //关闭子页面 } //window.opener.document....

    JS中表单的使用小结

    使用window.open()弹出的弹出窗口,刷新父窗口 window.opener.location.reload() 使用window.showDialog弹出的模式窗口 window.dialogArguments.location.reload(); 2.javascript弹出窗口的两种实现方式 —下面给...

    JS实现刷新父页面不弹出提示框的方法

    本文实例讲述了JS实现刷新父页面不弹出提示框的方法。分享给大家供大家参考,具体如下: A页面 open方式出 B... window.opener.location.reload(); window.opener = null; window.open('','_self'); window.close

    107个常用javascript语句

    89.window.location.reload()刷新当前页面. 90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回第几页,也可以使用访问过的URL) 91.document.write()不换行的输出,...

    JS中showModalDialog关闭子窗口刷新主窗口用法详解

    网上找了好长时间 大都是window.opener.location.reload(),等等 都不是我想要的 最后终于发现了一个 想知道的就往下看看吧 showModalDialog和showModelessDialog 一、showModalDialog和showModelessDialog有什么不同...

    javascript函数的解释

    24.指定当前显示链接的位置:window.location.href="URL" 25.取出窗体中的所有表单的数量:document.forms.length 26.关闭文档的输出流:document.close(); 27.字符串追加连接符:+= 28.创建一个文档元素:document....

    js setTimeout opener的用法示例详解

    opener.closed){ opener.location.reload(true); } setTimeout : 延迟多长时间执行什么方法,具体使用://www.jb51.net/article/35535.htm opener: 指parent表示父窗口,比如一个A页面利用iframe或frame调用B页面,...

    JS刷新父窗口的几种方式小结(推荐)

    浮层内嵌iframe及frame集合窗口,刷新父页面的多种方法 [removed] parent.location.reload(); [removed] [removed] ... window.opener.location.reload(); [removed] [removed] window.opener.location.

    JavaScript 定时器 SetTimeout之定时刷新窗口和关闭窗口(代码超简单)

    setTimeout("self.location.reload();",5000); //js 定时关闭窗口(ie和FF中测试过) //6秒后自动关闭当前窗口 setTimeout("window.opener=null;window.close()",6000); 下面给大家介绍下javascript定时器使用 使用...

    js关闭子窗体刷新父窗体实现方法

    代码如下: Code highlighting produced by Actipro CodeHighlighter (freeware)... //使用浏览器刷新功能 window.opener.location.reload(); 使用showModalDialog方法 window.returnValue = ‘refresh’;

    ajax提交整个from表单示例代码

    代码如下: $.ajax( { type : “POST”, url : “<%=request.getContextPath()%>/control/daControlAction_updateEmotecontrol.action”, data : $(“#form1”).serialize(), ... window.opener.location.reload

    javascript刷新父页面的各种方法汇总

    用iframe、弹出子页面刷新父页面iframe ...window.opener.location.reload(); [removed] 子窗口刷新父窗口 [removed] self.opener.location.reload(); [removed] 刷新以open()方法打开的窗口 [removed] win

    JAVASCRIPT下判断IE与FF的比较简单的方式

    但是过程相对复杂一点,... }else{ //FIREFOX opener.location.reload(); } window.close(); [removed]document.all这个属性,IE下可以使用,而FF下不能使用,利用这一点。就可以针对 不同的浏览器,来执行对应的程序。

    javascript刷新父页面方法汇总详解

    1.用iframe、弹出子页面刷新父页面... window.opener.location.reload(); [removed] 3.子窗口刷新父窗口 [removed] self.opener.location.reload(); [removed] 4.刷新以open()方法打开的窗口 <script language=J

Global site tag (gtag.js) - Google Analytics