刷新弹出窗口关闭时的父页面 [英] Refresh Parent page on close of pop up window

查看:80
本文介绍了刷新弹出窗口关闭时的父页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父页面,其中我添加了搜索功能。

如下

 函数FunClick(StrPriCaption){
var StrPriHTML =;
if(StrPriCaption =='AdvSearch'){
//document.getElementById('TxtCondition').value =AdvSearch;
//form1.submit();
var StrPriReturnValue =;
window.open('FrmInwardHdrAdvanceSearch.aspx',null,'height = 370,width = 630,top = 0,left = 0,resizable = yes,scrollbars = yes');





它完美地工作。它打开弹出式窗口页面供我搜索。



但现在我想要的是,如果我关闭弹出窗口,我想刷新父页面。



我在Child页面中尝试了以下代码,但未刷新父页面。

 函数CloseWindow(){
window.close();
window.opener.location.reload();
}

如何使用Javascript来做到这一点?


方法1

    <脚本> 
function popup(){
var win = window.open(,Page Title,toolbar = no,location = no);
win.document.body.innerHTML ='< a href =#onclick =window.opener.location.reload(); window.close();>关闭我< / a>' ;
}
< / script>
< a href =#onclick =popup()>打开我< / a>

它创建一个带有链接的弹出窗口,用于关闭窗口并刷新父窗口。



演示: https://jsfiddle.net/eke4f72r/



方法2

 < script> 
function popup(){
var win = window.open(,Page Title,toolbar = no,location = no);
var win_timer = setInterval(function(){
if(win.closed){
window.location.reload();
clearInterval(win_timer);
}
},100);
}
< / script>
< a href =#onclick =popup()>打开我< / a>

它从父窗口中检测孩子是否关闭。如果为true,则重新加载页面。



演示: https:/ /jsfiddle.net/gv6nmdn9/



编辑使用方法1时,让父母打开您想要的弹出窗口添加到你的孩子:

 < a href =#onclick =window.opener.location.reload() ; window.close();>关闭我< / a> 


I have a Parent page in which, I have added a search functionality.

like below

function FunClick(StrPriCaption) {
        var StrPriHTML = "";
        if (StrPriCaption == 'AdvSearch') {
            //document.getElementById('TxtCondition').value = "AdvSearch";
            //form1.submit();
            var StrPriReturnValue = "";
            window.open('FrmInwardHdrAdvanceSearch.aspx', null, 'height=370,width=630,top=0,left=0,resizable=yes,scrollbars=yes');

        }
 }

And it works perfectly. It opens a pop up window page for me to search for.

But now what I want is, IF I close the pop up,I want to refresh the parent page.

I tried with below code in Child page, but it didn't refreshed the parent page.

 function CloseWindow() {
    window.close();
    window.opener.location.reload();
 }

How can I do this using Javascript?

解决方案

Method 1

<script>
function popup() {
    var win = window.open("", "Page Title", "toolbar=no, location=no");
    win.document.body.innerHTML = '<a href="#" onclick="window.opener.location.reload();window.close();">Close Me</a>';
}
</script>
<a href="#" onclick="popup()">Open Me</a>

It creates a popup with a link to close the window and refresh parent.

Demo: https://jsfiddle.net/eke4f72r/

Method 2

<script>
function popup() {
    var win = window.open("", "Page Title", "toolbar=no, location=no");
    var win_timer = setInterval(function() {   
      if(win.closed) {
          window.location.reload();
          clearInterval(win_timer);
      } 
      }, 100); 
}
</script>
<a href="#" onclick="popup()">Open Me</a>

It detects from the parent window if child is closed. If true, it reloads the page.

Demo: https://jsfiddle.net/gv6nmdn9/

EDIT When using method 1, make your parent to open the popup you want and just add this in your child:

<a href="#" onclick="window.opener.location.reload();window.close();">Close Me</a>

这篇关于刷新弹出窗口关闭时的父页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆