【问题标题】:refresh parent page from child's child page从孩子的子页面刷新父页面
【发布时间】:2011-02-12 10:27:15
【问题描述】:

是否可以使用javascript从孩子的子页面刷新父页面。

我有一个打开子窗口的网络表单,子窗口上的一个按钮关闭当前子窗口并打开一个子子窗口。现在 subchild 上的按钮应该关闭窗口并刷新父窗体。

请给我建议。

谢谢。

对于按钮点击事件

父页面中的代码

函数fun()

{
 window.open('Child.aspx');    
 return false;
}

子页面中的代码

函数fun()

{
 window.close();
 window.open('SubChild.aspx');     
 return false;
}

【问题讨论】:

    标签: asp.net javascript


    【解决方案1】:

    你试过用这些吗?

    window.opener.reload();

    window.opener.location.reload();

    我认为 window.opener.opener.reload();可以工作..

    【讨论】:

    • 是的,我用过它们。但它只对一个专利子有效。
    【解决方案2】:

    看到您的代码后编辑。问题是您正在从第一个窗口打开第二个窗口并关闭第一个窗口,因此您没有参考回开瓶器。您可以改为在父窗口中调用方法来打开第二个窗口,这样父窗口仍然是您的开启者。

    Parent.html

    function openWindow(sURL){
      window.open(sURL);
    }
    

    Child1.html

    function fun(){
      window.opener.openWindow('Child2.html');     
      window.close();
    }
    

    Child2.html

    function fun(){
      window.opener.location.reload(true);     
    }
    

    【讨论】:

    • 给出错误。 “在 jscript 运行时中断。访问被拒绝”
    【解决方案3】:

    在您的子窗口中使用以下内容。

    <script type="text/javascript">
        function openwindow()
        {
            opener.document.location.reload(true);
        }
    </script>
    

    已编辑

    创建两个文件 1] 父.html

    <script type="text/javascript">
        function openwindow(url)
        {
        window.open(url, "mywindow","location=1,status=1,scrollbars=1,resizable=no,width=650,height=650");
        }
    </script>
    
    
    <a href="javascript: openwindow('/home/Salil/Desktop/child.html')">Open Child</a>
    

    2] child.html

    <script type="text/javascript">
        function openwindow()
        {
            opener.document.location.reload(true);
        }
    </SCRIPT>
    
    <a href="javascript: openwindow()">Refresh Parent</a>
    

    最新编辑

    在child1.html中写一个函数

    function child1()
        {
            opener.document.location.reload(true);
        }
    

    按如下方式调用 child2.html 中的函数

    function child2()
    {
        window.opener.child1();
    
    }
    

    【讨论】:

    • 是在打开子窗口之前吗?
    • 检查我的编辑版本并在浏览器中打开 parent.html 然后测试。
    • 我想从孩子的子窗口刷新父母
    • 请查看我编辑的最新答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多