/ Published in: jQuery
URL: http://www.fyfi.net
Easy way to replace all youtube.com links with embed flash video on page or blog post/posts.
Go to youtube.com, find the video (for example http://www.youtube.com/watch?v=zzk-8akrWxo), copy link and paste it in your page/blog post.
Change in script width and height to your desired parameters and change '#blog .post' to your page content container or blog post container.
Live preview can be seen here - http://motorolleri.lv/blogs/
That's it :) Enjoy.
Expand |
Embed | Plain Text
$(function(){ var vidWidth = 459; // youtbe video width var vidHeight = 283; // youtube video height var obj = '<object width="' + vidWidth + '" height="' + vidHeight + '">' + '<param name="movie" value="http://www.youtube.com/v/[vid]&hl=en&fs=1">' + '</param><param name="allowFullScreen" value="true"></param><param ' + 'name="allowscriptaccess" value="always"></param>' + '<param name="wmode" value="transparent"></param><em' + 'bed src="http://www.youtube.com/v/[vid]&hl=en&fs=1" ' + 'type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" ' + 'allowfullscreen="true" width="' + vidWidth + '" ' + 'height="' + vidHeight + '"></embed></object>'; $('#blog .post').find('p:contains("youtube.com/watch")').each(function(){ var that = $(this); var vid = that.html().match(/(?:v=)([\w\-]+)/g); if (vid.length) { $.each(vid, function(i){ that.replaceWith( obj.replace(/\[vid\]/g, this.replace('v=','')) ); }); } }); });
Comments
Subscribe to comments
You need to login to post a comment.

its cool...thanks for script my brooo \m/