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

Link to comment
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.