質問

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