嗨,大家好我正在使用這個函數打開一個彈出窗口並在3秒後關閉它。彈出窗口成功打開,但settimeout函數不起作用,並最終不關閉打開的彈出窗口。 我在這裏做錯了什麼?Javascript settimeout不關閉彈出框
<script type="text/javascript">
function popUp(id,entry,escape)
{
popupWindow = window.open('process_concur.php?id='+id+'&entry='+entry+'&escape='+escape,'Concur','resizable=yes,scrollbars=yes,width=250,height=250');
popupWindow.focus();
setTimeout(function() { popupWindow.close();}, 3000);
}
//reload the current window when the popup is closed.
function popUpClosed() {
window.location.reload();
}
</script>
這將打開彈出頁面(代碼)
<?php
include 'classes/class.user.php';
$userMain = new user();
//get parameters
$id = isset($_GET['id']) ? $_GET['id'] : '';
$entry = isset($_GET['entry']) ? $_GET['entry'] : '';
$escape = isset($_GET['escape']) ? $_GET['escape'] : '';
//now, $escape is sha1 and $entry is base64 encoded..decode entry and check if sha1 of decoded entry matches escape
$dentry = base64_decode($entry);
if(sha1($dentry)==$escape)
{
//process concur
if($userMain->reviewExists($id))
{
if($userMain->increaseConcur($id))
{
echo "Done";
exit();
}
}
else
{
//review doesnt no exist
echo "Some problems occured at id doesn't exist";
}
}
else
{
echo "Some problems occured dentry";
}
?>
<script>
window.onunload = function() {
if (window.opener && !window.opener.closed) {
window.opener.popUpClosed();
}
};
</script>
如果您使用jQuery模式,會不會更好? –
@MihaiIorga這與問題有什麼關係? – feeela
調用'popUpClosed()'在哪裏? – edi9999