문제

How can I make a popup alert window in a php site, depending by a variable, not by clicking a link or button?

example:

if ($a==1) {
alert(Good value!);
}else{
alert(Wrong value!);
}
도움이 되었습니까?

해결책

PHP itself can't interact with the client. You will have to have the PHP script output a JavaScript solution.

echo '<script type="text/javascript">';
if ($a==1) {  
  echo "alert('Good value!');";
}else{
  echo "alert('Wrong value!');";
}
echo '</script>';

다른 팁

Not a realy smart solution... People with a popup blocker wont see the popup... I prefer to jQuery with some HTML and PHP. If you wanne use it with POST data, try some AJAX, realy helps a lot. If you wanne use it for a POST, i can write you a small piece of code if you would like, let me know

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top