I'm trying to execute the following code from php:
echo '<script type="text/javascript">
var script = document.createElement("script");
var executefunction = "'."
$.jAlert({
'title': 'Alerta de Mesa de Control ',
'content': '".$why."',
'theme': 'green',
'btns': {
'text': 'Cerrar',
'onClick' : function(){
window.WWC(id,name);
window.location.reload(true);
}
},
'onClose': function(){
window.WWC(id,name);
window.location.reload(true);
},
});';
script.innerHTML = executefunction;
document.body.appendChild(script);
</script>".'"';
The main idea was that once the javascript code enters html , take the jquery tag and paste it in body
at the end.
but I get an error:
Uncaught SyntaxError: Invalid or unexpected token por el $.jAlert.
Update
Trying to declare it as a function and store it as string
:
<script>
document.addEventListener('DOMContentLoaded', function(event) {
var script = document.createElement('script');
var executefunction = new function (".'"'."$.jAlert({'title': 'Alerta de Mesa de Control ','content': '" . $why . "','theme': 'green','btns': {'text': 'Cerrar','onClick' : function(){window.WWC(id,name);window.location.reload(true);}},'onClose': function(){window.WWC(id,name);window.location.reload(true);},})".'"'.");
script.innerHTML = executefunction();
document.body.appendChild(script);
});
</script>
I stay as follows:
echo "<script type='text/javascript'>
$.jAlert({
'title': 'Alerta del Sistema',
'class': 'usertimer',
'content': '".$why."',
'theme': 'red',
'closeBtn': true
});
</script>";