Click here to Skip to main content
13,088,711 members (53,693 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, I'm a newbie, so apologies if this is a dumb question or in the wrong place or wrong format.
Below is some code which I'm using to display embedded YouTube videos from a playlist (banners[] ).

Everything works fine except that I cannot get the embedded YouTubes to allow full screen, despite the "allowfullscreen" in the document.write.

Can anyone tell me where I'm going wrong? The script is lifted from elsewhere, and I've only made minor modifications, so I'm a little out of my depth. It sits in the body of an HTML document, inside a div (but it makes no difference if I take it out of the div).

(Incidentally, if I just copy and paste a full YouTube embed code, it works fine and allows full screen).

Any help appreciated - thanks!
(code follows):

function random_banner(){
var i=0;
banners = new Array();
banners[0] = '4ErEBkj_3PY';
banners[1] = 'XH-groCeKbE';
banners[2] = 'UhlvEIxFM1k';

return banners[Math.floor(Math.random()*banners.length)];

document.write('<object width="425" height="344"><param name="movie" value="' + random_banner() + '&hl=en&fs=1fs=1&autoplay=1"></param><param name="allowfullscreen" value="true"></param><embed src="' + random_banner() + '&hl=en&fs=1fs=1&autoplay=1" allowfullscreen="true" width="510" height="413"></embed></object>')
Posted 2-Sep-12 10:07am
Updated 2-Sep-12 10:11am
Kenneth Haugland 2-Sep-12 16:49pm
You should leave a comment instead :) The Solution are only for actual solutions to your problem, not anything else :)
PaulHdear 2-Sep-12 16:55pm
OOps. Thanks again. Is there a record here for the greatest number of fundamental errors in a single post?

I see my "solution" was deleted - thanks. Does this mean that the question is still open?
Kenneth Haugland 2-Sep-12 17:04pm
Yep, its still open... A secound thing is that if there is a solution people wont always check your question, so you might miss some replies...
Ed Nutting 2-Sep-12 17:11pm
Out of interest, why on earth are you using old-style YouTube embed code? Much better to go back to YouTube and get the new iFrame method - more reliable and will probably solve your issue. It would also be "cleaner" code too and would allow YouTube to work its magic at getting videos to work on mobiles (iOS & Android) and all other platforms using HTML5. What you have will be very limited in compatibility compared to if you used the new method.

Try putting in the iFrame code - I bet it solves your bugs! Hope this helps,

Edit: By the way, it's probably because the browser isn't loading your written HTML properly since it's written after the proper page load cycle which is almost certainly crucial for this to work properly. If you use the iFrame method though, that won't be an issue because all browsers do support writing in an iFrame and immediately loading it - trust me, I've used it.
PaulHdear 2-Sep-12 17:47pm
As to why the old-style code: only because the script I lifted from elsewhere used the old-style embed, and I don't yet know enough to be able to adapt it to the new-style code. I'm sort of stuck between using something as a 'black box' and understanding it enough to tinker. A little knowledge...

As to the position of the script - I tried moving it to the end of the "head" (instead of having it in the body), but it still doesn't give me a fullscreen option; is that what you meant?

I also appreciate that a full answer to my question might need me to have learned a lot more of the fundamentals before I can make sense of it. I guess it's a bit like an air traffic controller getting a call from someone at 40,000ft asking which button makes the plane land!
PaulHdear 2-Sep-12 19:24pm
OK - I have bypassed the problem (mostly) by embedding a YouTube Playlist instead of trying to embed a "playlist" built in the web page itself. This seems like a cleaner solution.
But it raises another question. Can I pass parameters to the embedded youtube playlist so that:
(a) it starts playing as soon as the page loads
(b) it starts at a randomly chosen video in the playlist
(c) the "Playlist" button in the youtube window is turned "on" so that my playlist appears at the bottom of the video window?

So many questions...(perhaps I should close this question and post a new one on embedded playlists?)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 2 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100