Jump to content

Recommended Posts

I'm trying to use a 3rd party app for commenting inside a PHP variable.

 

The app code I'm trying to include:

<script>
var idcomments_acct = '12345';
var idcomments_post_id;
var idcomments_post_url;
</script>
<script type="text/javascript" src="http://www.website.com/script.js"></script>

 

I'm trying to put it into a variable like:

$output .= "<script>";
$output .= "var idcomments_acct = '12345'\;";
$output .= "var idcomments_post_id\;";
$output .= "var idcomments_post_url\;";
$output .= "</script>";
$output .= "<script type=\"text/javascript\" src=\"http://www.website.com/script.js\"></script>";

 

and finally render it in the HTML by using:

<?php echo $output; ?>

 

 

I'm not getting any errors but nothing is showing up either.  Is this just basically not allowed, did I forget to escape something, is my approach all wrong, what?

Link to comment
https://forums.phpfreaks.com/topic/188103-putting-some-java-inside-php/
Share on other sites

first off, thats Javascript, not Java.

 

Secondly, that looks fine, but that javascript doesn't look like it will do anything (unless the external script does something) What do you expect it to do, and what is it actually doing. Have you looked in the error console to make sure there is no errors

 

Have you tried just putting the script directly in the HTML? I don't see why you are putting it in PHP in the first place.

 

 

on a second glance, you don't need to escape semi colons, so try removing the backslashes that are infront of the semi colons. That will cause a javascript syntax error

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.