How to do it?
echo '<script>alert("hello");</script>';
Does anyone know how to execute JavaScript with PHP? I need this one. I know that all JavaScript has to be executed at the AJAX level. But the situation requires JavaScript to execute, that PHP is returning as an answer.
Regards
Javascript PHP, PHP , JS - . eval Javascript .
eval
AJAX:
$('#yourButton').onclick(function(){ //make your ajax request $.ajax({ url : "url", success : function(resp){ //resp is the javascript code sent back from PHP //eval it eval(resp); } }) });
javascript :
"alert(\"hello\");"
:
var js = ajax.r;
eval(js);
, .
Eval will work, but be careful.
If custom content can get into your eval statement, someone can use it to create a malicious script for your site.
Just a head.