I want to display YouTube videos on my website, but I need to be able to add a unique id
for each video that's going to be shared by users. So I put this together, and I have run into a little problem. I am trying to get the JavaScript to add a random string for the div id
, but it's not working, showing the string:
<script type='text/javascript' src='jwplayer.js'></script> <script type='text/javascript'> function randomString(length) { var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split(''); if (! length) { length = Math.floor(Math.random() * chars.length); } var str = ''; for (var i = 0; i < length; i++) { str += chars[Math.floor(Math.random() * chars.length)]; } return str; } var div = randomString(8); </script> <div id='div()'>This text will be replaced</div> <script type='text/javascript'> jwplayer('div()').setup({ 'flashplayer': 'player.swf', 'file': 'http://www.youtube.com/watch?v=4AX0bi9GXXY', 'controlbar': 'bottom', 'width': '470', 'height': '320' }); </script>
I really like this function:
function guidGenerator() { var S4 = function() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }; return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); }
From Create GUID / UUID in JavaScript?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With