【问题标题】:How to refresh parent page once the child page is closed and they both are not on same server?子页面关闭后如何刷新父页面并且它们都不在同一台服务器上?
【发布时间】:2012-11-22 07:35:28
【问题描述】:

我在一台服务器上有一个父页面,我将一个子页面称为另一个服务器上的弹出窗口。因此,一旦子页面关闭,我想刷新父页面,所以我在父页面中编写了一个重新加载函数,我试图从子页面调用它:

opener.reload();

但是由于父母在另一台服务器上,所以这件事不起作用,有什么办法可以实现吗?

【问题讨论】:

  • 您的子页面是否有不同的服务器 url?
  • 是的,父页面在 clorderdev2.uvacha.com/login.aspx,子页面在 button.uvacha.com/login.aspx
  • @rink.attendant.6:当两个表单都驻留在一个服务器上时,这些东西会起作用,但我的两个表单都在不同的服务器上
  • @SwatiAwasthi 我已经发布了一个我刚刚测试过的答案。

标签: javascript jquery asp.net


【解决方案1】:

而不是opener.reload

你可以使用submit()

在你的 javascript 函数中类似这样的东西

opener.document.forms[0].submit(); 

源文档

http://forums.asp.net/t/1412827.aspx/1

【讨论】:

    【解决方案2】:

    您能告诉我如何在弹出窗口中打开子页面吗?如果通过颜色框或厚框,则有一个 onClose 事件,您可以在其上编写类似

    的内容
    function() 
    { 
        window.location.reload(true); 
    }
    

    【讨论】:

    • 我正在使用 var popupWindow = window.open("URL", 'popUpWindow', 'height=350,width=550,left=550,top=300,resizable=yes,scrollbars=yes, toolbar=yes,menubar=no,location=no,directories=no,status=yes')
    • 试试这种方式..在你的父页面上写一个函数,当你关闭弹出窗口时从pop调用一个函数,比如window.opener.parentFunction();在这个函数下你可以写 window.location.reload(true);
    • 我就是这样做的,但是由于父页面在另一台服务器上,'opener' 的东西不起作用
    • 尝试另一件事,调用包含一些查询字符串的页面,在客户端检查该查询字符串是否存在,使用 window.location.reload() 重新加载页面;
    【解决方案3】:

    在父页面中尝试这个 Javascript 函数

     function GoTopage()
        {
         var retValue = showModalDialog ("child.aspx", "", "dialogWidth:600px; dialogHeight:300px; dialogLeft:200px;");
         if (retValue == null)
         {
         __doPostBack('', '');  /* For postback */  
         /*location.reload();  for complete reloading or refreshing*/
         }
         return false;
    
        }
    

    【讨论】:

    • @Swati Awasthi:请参阅编辑后的答案。我已将其删除。
    • 弹出窗口即将到来,但子页面内的代码似乎没有执行
    • 它会在打开弹出窗口时尝试删除缓存(使用这个)'Response.Cache.SetCacheability(HttpCacheability.NoCache);'
    • 在 javascript 控制台中显示错误 _doPostBack is not defined
    • 它是 __doPostBack 而不是 _doPostBack
    【解决方案4】:

    这并不是一个很好的方法,但这是我能想到的唯一方法,因为有同源策略。

    var timer, childWindow = window.open("https://google.ca/");
    
    function hasClosed() {
        'use strict';
        if (childWindow && childWindow.closed) {
            // stop the timer
            window.clearInterval(timer);
    
            // do whatever here
            console.log('The window has closed');
        }
    }
    
    // set a timer to continually check if the window has closed
    timer = window.setInterval(hasClosed, 1000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多