最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to refresh the parent page and closing the child window using javascript - Stack Overflow

programmeradmin1浏览0评论

How to refresh the parent page and closing the child window using javascript when I click the button in parent page asp I am able to refresh the parent page but my child window is not closing. My C# Code is

 string script = @"<script>
        function RefreshParent()
        {
          window.close();
           window.opener.location.reload();
          }RefreshParent();
</script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "ssr", script);

How to refresh the parent page and closing the child window using javascript when I click the button in parent page asp I am able to refresh the parent page but my child window is not closing. My C# Code is

 string script = @"<script>
        function RefreshParent()
        {
          window.close();
           window.opener.location.reload();
          }RefreshParent();
</script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "ssr", script);
Share Improve this question edited Sep 12, 2012 at 6:38 lc. 117k21 gold badges161 silver badges188 bronze badges asked Sep 12, 2012 at 6:35 LakkiLakki 652 silver badges6 bronze badges 1
  • try to call reload() method before window.close(); – opewix Commented Sep 12, 2012 at 6:38
Add a ment  | 

4 Answers 4

Reset to default 1

Try

window.parent.location.reload();

just try this code in your child window

Page.ClientScript.RegisterStartUpScript(this.GetType(),
                                       "close",
       "<script language=javascript>window.opener.location.reload(true);
                      self.close();</script>");

Example with a link:

<script language="Javascript">
<!-- Start
document.write('<a href="javascript:self.close()" onClick="opener.location.reload(true);">Close</a>');
// Stop -->
</script>

You are closing your child window before your parent window gets refreshed. Try it this way

<string script = @"<script>
            function RefreshParent()
            {
              window.opener.location.reload();
              window.close();              
              }RefreshParent();
    </script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "ssr", script);
发布评论

评论列表(0)

  1. 暂无评论