我想用PHP做一些事情,然後窗口應該關閉。Body onload腳本在PHP腳本之前執行
這是代碼:
<?php
do_this_in_server();
do_that();
?>
<html>
<head>
<script>
function realClose()
{
var win=window.open("","_top","","true");
win.opener=true;
win.close();
}
</script>
</head>
<body onload="realClose()">
</body>
的JavaScript,因此PHP功能已完成之前執行窗口的閉合。有任何想法嗎?
這些功能是做什麼的?你怎麼知道他們沒有完成? – eol
更好地使用ajax並獲得json響應,然後調用realClose函數 – Kotzilla
在PHP腳本完成之前,不可能執行JS。 PHP完成後,完整的HTML只發送給瀏覽器。 –