1

I have created a javascript file in github

The code in the js file is as follows :

function youTube(a,b,c,d)
{
 return ("<iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+a+"' width='210'/><iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+b+"' width='210'/><iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+c+"' width='210'/><iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+d+"' width='210'/>");
}

I used rawgit.com to create a CDN link and put it in script source(src)
And in Blogger>>Edit HTML, at the appropriate place where I wanted it I put the code :

<script src='https://cdn.rawgit.com/example/CTGod/1bc76937/youtubebar.js' type='text/javascript'>
var a="zK5zn44YzKA";
var b="3d21j6xOejU";
var c="U8gD0XiOOL4";
var d="cLnR-L6fNqs";
document.write(youTube(a,b,c,d));
</script> 

When I did not use the code that I have right now put in an external js file and used it normally it worked. The code looked like the below :

<script type='text/javascript'>
var a="zK5zn44YzKA";
var b="3d21j6xOejU";
var c="U8gD0XiOOL4";
var d="cLnR-L6fNqs";
function youTube(a,b,c,d)
{
  return ("<iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+a+"' width='210'/><iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+b+"' width='210'/><iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+c+"' width='210'/><iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+d+"' width='210'/>");
}

document.write(youTube(a,b,c,d));
</script>

Now, I want to know why the code ,which when put in external js file doesn't work.
If I need to change my source of js file tell me where to upload and how to use it the best way.

1
  • Have you tried splitting 2 tags <script>? like: <script src='https://cdn.rawgit.com/yashas123/CTGod/1bc76937/youtubebar.js' ></script> <script type='text/javascript'> var a="..."...</script> Commented May 8, 2017 at 16:33

1 Answer 1

2

You have to use a separate script tag to render external js file like the following

<script src='https://cdn.rawgit.com/yashas123/CTGod/1bc76937/youtubebar.js' type='text/javascript'/>

<script type='text/javascript'>
  var a="zK5zn44YzKA";
  var b="3d21j6xOejU";
  var c="U8gD0XiOOL4";
  var d="cLnR-L6fNqs";
  document.write(youTube(a,b,c,d));
</script> 
Sign up to request clarification or add additional context in comments.

6 Comments

Ok, it's halfway there. Now is to debug the external JS, only the first iframe code : <iframe allowfullscreen='1' frameborder='0' height='140' src='https://www.youtube.com/embed/"+a+"' width='210'/> works. Other iframe codes not working and the the footers and others texts below the code part is not loading anymore. Any fix?
This happend because of using documet.write try to use innerHTML with a div Id instead.
Ok...I'll try it out and tell the results tomorrow since it's already nearly 12AM IST here. Thanks :D
I need help, how to pass on the values of a,b,c,d while I am using innerHTML and div id?
What I did was put the iframes in <p id='yT'> ......</p> and used document.getElementById("yT").innerHTML; by putting it in a function.
|

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.