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 Quote Link to comment 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). Quote Link to comment 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 ? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.