Jump to content

how do you call a javascript method within php code?


sullyman

Recommended Posts

 

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.