sullyman Posted December 13, 2007 Share Posted December 13, 2007 Hi, I need to run the following javascript within php code. <script type="text/javascript"> var uri = 'http://terfs.xxxxxxxx.com/imp?type(js)g(16188744)a(1353278)' + new String (Math.random()).substring (2, 11); document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>'); </script> How can i implement the above within the following please. Is the following correct? <?php echo "<script>javascriptfunction();</script>"; ?> Thanks Link to comment https://forums.phpfreaks.com/topic/81580-how-do-you-call-a-javascript-method-within-php-code/ Share on other sites More sharing options...
wildteen88 Posted December 13, 2007 Share Posted December 13, 2007 PHP cant call javascript. PHP and Javascript is ran at different intervals. PHP is parsed on the server side whereas JavaScript is parsed via the web broweser (client side). Link to comment https://forums.phpfreaks.com/topic/81580-how-do-you-call-a-javascript-method-within-php-code/#findComment-414280 Share on other sites More sharing options...
sullyman Posted December 13, 2007 Author Share Posted December 13, 2007 I thought that you could echo it and it would be displayed on the html page ? Link to comment https://forums.phpfreaks.com/topic/81580-how-do-you-call-a-javascript-method-within-php-code/#findComment-414281 Share on other sites More sharing options...
wildteen88 Posted December 13, 2007 Share Posted December 13, 2007 I thought that you could echo it and it would be displayed on the html page ? Yes you can do that. But PHP wont be calling the javascript code as such. Link to comment https://forums.phpfreaks.com/topic/81580-how-do-you-call-a-javascript-method-within-php-code/#findComment-414284 Share on other sites More sharing options...
sullyman Posted December 13, 2007 Author Share Posted December 13, 2007 Do you know how to do same? Link to comment https://forums.phpfreaks.com/topic/81580-how-do-you-call-a-javascript-method-within-php-code/#findComment-414285 Share on other sites More sharing options...
sullyman Posted December 13, 2007 Author Share Posted December 13, 2007 Anyone know how i could this? Maybe i can run a print command to get the javascript to display? Link to comment https://forums.phpfreaks.com/topic/81580-how-do-you-call-a-javascript-method-within-php-code/#findComment-414369 Share on other sites More sharing options...
helraizer Posted December 13, 2007 Share Posted December 13, 2007 Hi, I need to run the following javascript within php code. <script type="text/javascript"> var uri = 'http://terfs.xxxxxxxx.com/imp?type(js)g(16188744)a(1353278)' + new String (Math.random()).substring (2, 11); document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>'); </script> How can i implement the above within the following please. Is the following correct? <?php echo "<script>javascriptfunction();</script>"; ?> Thanks What you have there will work fine. Although, in your javasript you'd have: <script type="text/javascript"> function javascriptfunction() { var uri = 'http://terfs.xxxxxxxx.com/imp?type(js)g(16188744)a(1353278)' + new String (Math.random()).substring (2, 11); document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>'); } </script> That way you're calling the javascript just as you would with HTML. Just out of interest in your javascript, in your document.write() why do you have '<sc'+'ript... why not just '<script type="text/javascript" src="'...etc... ? Sam Link to comment https://forums.phpfreaks.com/topic/81580-how-do-you-call-a-javascript-method-within-php-code/#findComment-414390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.