Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
4.00/5 (1 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!
Paul
(code follows):


JavaScript
<SCRIPT LANGUAGE="JavaScript">
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="http://www.youtube.com/v/' + random_banner() + '&hl=en&fs=1fs=1&autoplay=1"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.youtube.com/v/' + random_banner() + '&hl=en&fs=1fs=1&autoplay=1" allowfullscreen="true" width="510" height="413"></embed></object>')

</SCRIPT>
Posted
Updated 2-Sep-12 10:11am
v2
Comments
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 :)
[no name] 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?
Paul
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,
Ed

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.
[no name] 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!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900