关闭弹出窗口时如何刷新页面..? [英] How to refresh the page when i close the popup window..?

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

问题描述



关闭弹出窗口时如何刷新页面..


看到我的代码
-------------

< a href =#" onclick ="window.close();" class ="Content">关闭窗口</a>

我想在关闭弹出窗口时立即刷新或重新加载父窗体..

Hi,

How to refresh the page when i close the popup window..?


see my code
-------------

<a href="#" onclick="window.close();" class="Content">Close Window</a>

I want, when i close the popup window, immediately the parent form should get refresh or reload..

How to do this...?

推荐答案

有几种方法,但一种简单的方法可能是
There are several ways but one simple way could be
function closeandrefresh(){
  opener.location.href = opener.location.href;
  window.close(); 
}



并将您的链接更新为

< a href =#" onclick ="closeandrefresh();" class ="Content">关闭窗口</a>



And update your link as

<a href="#" onclick="closeandrefresh();" class="Content">Close Window</a>


亲爱的可以通过AJAX ............
Dear it is possible through AJAX............


您可以在父窗口中使用递归函数来等待弹出窗口关闭.例如

You can use a recursive function in the parent window to wait for the popup to close. E.g.

<html>
<head>
<script type="text/javascript">


var generator = null;
function show_prompt()
{
    //Open a popup and store the handler in a var named generator
    generator = window.open("", "New Popup", "width=400, height=400");
    //Add some html to the new window
    generator.document.write("<html><head><title>Test</title></head><body>");
    generator.document.write("<p><a href=\"javascript:self.close()\"> Close</a></p>");
    generator.document.write("</body></html>");
    generator.document.close();
    generator.focus();
    
    //The crucial line! Start the recursive function that will poll the new popup window until it's closed. 
    WaitForClose();
}
function WaitForClose()
{
    //Check to see if the popup has been closed
    if(!generator.closed)
    {
        //If not, recall this function - the recursion
        setTimeout("WaitForClose()", 500);
    }
    else
    {
        //If popup has been closed, call the PopupClosed funtion
        PopupClosed();
    }
}
function PopupClosed()
{
    //Do something here!
    alert("x");
}


</script>
</head>
<body>
<input type="button" onclick="show_prompt()" value="Show prompt box" />
</body>
</html>



希望这会有所帮助,

埃德:)



Hope this helps,

Ed :)


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

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