浏览器重新加载时重新打开的弹出窗口:

时间:2015-06-10 15:07:59

标签: javascript php

openerWindow.php会通过按钮调用openedWindow.html,但为什么当我关闭openedWindow.html并刷新浏览器时,此openedWindow会再次显示?这个弹出窗口不是通过按钮触发的。我无法弄明白,为什么以及如何解决这个问题:

openerWindow.php

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<form method="post" action="">
<input type="submit" name="open" value="open pop up" onclick=""/>

<?php
if(isset($_POST["open"])){ // if button clicked call other html page as pop up

?>
    <script >
    newWindow = window.open('openedWindow.html', 'formUntukUpte', 'width=400,height=350');


   </script>
<?php
}
?>

</form>
</body>
</html>

openedWindow.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
</html>

我真的很感谢你的帮助,

1 个答案:

答案 0 :(得分:0)

刷新浏览器时可能会保留帖子数据。

您可以通过在页面中添加<?php print_r($_POST); ?>进行检查,然后您会看到帖子数据是否仍然存在。

似乎这在javascript中更容易做到:

<button onclick="window.open('openedWindow.html', 'formUntukUpte', 'width=400,height=350')">Open Popup</button>

如果您需要在PHP中执行此操作,则需要在会话var中存储值,例如:

<?php
session_start();
if (isset($_POST['open'] && !isset($_SESSION['popup_shown'])) {
$_SESSION['popup_shown'] = true;
?>
<script>
//popup launch
</script>
<?php
}
?>
相关问题