【问题标题】:Refresh part of parent when child window closes子窗口关闭时刷新父级的一部分
【发布时间】:2015-05-28 10:59:18
【问题描述】:

第 1 页:tabeloverzicht.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tabel overzicht</title>
<link href="../css/templatemo_style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../css/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function() {
    $(document).ready(function() {      
        $.get(
        'tabel.php', 
        function(response){
            $('#tabelplaats').html(response);
        }
    );
    });

    $(window).click(function(event){
        $.get(
        'tabel1.php',
        function(response){
            $('#tabelplaats').html(response);
        }
    );
}); 
});
</script>
</head>

<body>
<div id="tabelplaats">

</div>
</body>
</html>

第2页:tabel.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../css/templatemo_style.css" rel="stylesheet" type="text/css" />
<title>Tabel Processor</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "',  'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,h eight=500,left = 200,top = 200');");
}
// End -->
</script>
</head>

<body>

<table>
<tr>
    <th>Hallo</th>
    <th>dit</th>
    <th>is</th>
</tr>
<tr>
    <td>een</td>
    <td>test</td>
    <td><a HREF="javascript:popUp('popup.php')"><div id="modify" class="buttonsmall"><button id="BedrijfAanpassen" class="button" name="modify"><i class="icon-pencil icon-small"></i></button></div></a></td>
</tr>
</table>

</body>
</html>

第 3 页:Tabel1.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../css/templatemo_style.css" rel="stylesheet" type="text/css" />
<title>Tabel Processor</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500,left = 200,top = 200');");
}
// End -->
</script>
</head>

<body>

<table>
<tr>
    <th>Test</th>
    <th>test</th>
    <th>test</th>
</tr>
<tr>
    <td>test</td>
    <td>test</td>
    <td>test</td>
</tr>
</table>

</body>
</html>

第4页:popup.php


不管这个页面上的什么。

Tabeloverzicht 是主页。这是显示的表格。该表格包含一个打开弹出窗口的按钮(在我的应用程序中,您可以在弹出窗口中更改表格的某些值)当弹出窗口关闭时,他需要更新父窗口中的表格。 window.opener.reload(true) 对我不起作用,因为主页上还有许多其他选项也会被重置。我只需要更新顶表。

在我的应用程序中还有第二个表格,根据打开的弹出窗口,他需要刷新第一个或第二个表格。

希望任何人都可以提供帮助,因为我已经被这个问题困扰了好几天了......

提前致谢!

【问题讨论】:

  • 假设表中的值来自数据库,您需要执行 AJAX 调用来更新该特定表。查看此链接了解更多详情:(stackoverflow.com/questions/12458540/…)。
  • 你能不能用一些小东西来总结一下,而不是把所有的东西都扔掉。 :)

标签: javascript php jquery window


【解决方案1】:

在我看来,你需要在主页和里面有一个回调函数,你可以做任何事情......

例如: index.html

<html>
    <head>
        <SCRIPT LANGUAGE="JavaScript">
            <!-- Begin
            function popUp(URL) {
                day = new Date();
                id = day.getTime();
                eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500,left = 200,top = 200');");
            }
        // End -->
            function callback_top(){
                console.log("callback_top()");
            }

        </script>
    </head>
    <body>
        <button onclick="popUp('pop.html');">Press me</button>
    </body>
</html>

pop.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript">
        // solution 1
        function calltop(){
            window.opener.callback_top();
        }
        // solution 2
        window.onbeforeunload = function(){
            window.opener.callback_top();
        }
    </script>
</head>
<body>
    <button onclick="calltop();">Press me 2</button>
</body>
</html>

【讨论】:

    猜你喜欢
    • 2011-01-19
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    相关资源
    最近更新 更多