1

I need to embed a player by the following code:

<script type="text/javascript" src=***the url***></script>

A part in the url is the ID which is retrieved from mySQL database. I know that the string concatenation can't be directly handled in the src, so I add the function in the beginning:

<head>
<script>
function call(url)
{
  var script = document.createElement('script');
  script.type="text/javascript";
  script.src = url;
  document.body.appendChild(script);
}
</script>
</head>

In the body,

<body>
  <?php ***...to retrieve ID***?>
  <script type="text/javascript"> 
    var videoid = "<?php echo $id; ?>";  //Transfer ID to javascript 
    var url="http://......"+videoid;   //Url string finished
    call(url);   //Function call
  </script>

Now the script is appended, but I can't see the player. Why?

7
  • check the console.is there any error messages? Commented Jul 14, 2016 at 17:36
  • If you check the network tab of the browser, is it actually pulling in the js script? Commented Jul 14, 2016 at 17:36
  • I would suggest not using the keyword call as a function name. Use appendScript or something more obvious... Commented Jul 14, 2016 at 17:37
  • Is the DOM inspector displaying the correct URL and script tag? What happens when you copy paste the url from the tag into the browser? Commented Jul 14, 2016 at 17:38
  • Try this ways stackoverflow.com/questions/11150409/… Commented Jul 14, 2016 at 17:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.