簡體   English   中英

調用JavaScript警報后無法執行php代碼

[英]php code not executing after calling a javascript alert

我在調用javascript警報后無法執行php重定向時遇到麻煩。 代碼如下:

echo '<script>window.alert("This device is aleady registered to another user");</script>';
header('Location: page.php');

在警報上單擊“確定”后,重定向將不會執行。 關於如何使此代碼正常工作的任何想法?

謝謝

輸出后無法發送標題。 只需通過JavaScript一直重定向用戶即可。

echo '<script>window.location.href = "page.php";</script>';

在調用header之前,您甚至無法輸出任何內容,甚至沒有一個空格。 您可以在輸出腳本之前使用標頭,如下面的代碼所示

header('Location: page.php');
echo '<script>window.alert("This device is aleady registered to another user");</script>';

希望這對您有幫助

這是最好的使用方法:

window.location

http://www.w3schools.com/js/js_window_location.asp

嘗試這種方式

echo '<script>window.alert("This device is aleady registered to another user");
window.location.href = "page.php";
</script>';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM