first of all, you must write javascript code like this :
function randomRange(l,h){ var range = (h-l); var random = Math.floor(Math.random()*range); if (random === 0){random+=1;} return l+random;}
function get_random_yid(){ var ids = document.getElementsByClassName("youtube-id"); var idx = randomRange(ids.length,0); return ids[idx].getAttribute("id");}
function frx_ytb_show(autoPlay){ var videos = document.getElementsByClassName("youtube-frame"); for (var i=0; i<videos.length; i++) { var youtube = videos[i]; var yid = get_random_yid(); youtube.setAttribute("id", yid); youtube.style["position"]="relative"; if(autoPlay) youtube.setAttribute("src", "https://www.youtube.com/embed/" + youtube.id + "?autoplay=1&autohide=1&border=0&wmode=opaque&enablejsapi=1"); else youtube.setAttribute("src", "https://www.youtube.com/embed/" + youtube.id + "?autohide=1&border=0&wmode=opaque"); }}
copy and save to file, or you can download here :
go to your blogger dashboard or you site html, then add the script:
i use blogger for this example.
1. edit html
1. edit html
2. add script
3. Search </body>
4. call the script before </body>
set parameter 1 will make script to play youtube video automatically.
5. Add your video-id list (multiple video id)
at this example i use a gadget to put video list.
i also put youtube frame here ( you may put at any places on your web/blogger)
you can put another youtube frame (viewer) (multiple youtube frame)
2 comments
Is there a way to set parameters. For instance, the video has to be a song or the video has to be recommended for the viewer.
ReplyThis is a great post.
ReplyI was just looking how to make my site interesting when I saw this.
Post a Comment