Here is a simple JavaScript bookmarklet that replaces YouTube videos embedded using the old flash object embed method with the new iframe embed method. What this means is that you can force a lot of embeded YouTube videos to play with the HTML5 video player. This is particularly useful on IOS devices (iPhone, iPad) with the YouTube app disabled.
Installation (iPad)
- Add this page as a bookmark
- Select and copy the Javascript in the textarea below.
- Go to your bookmarks and tap “edit”. Then tap the new bookmark you just made of this page.
- Edit the name and paste the Javascript in the field for the URL.
- Click done.
Source code with formatting
javascript:(function(){
var objectTags = document.getElementsByTagName('object');
var objectTagsArr = new Array();
for (var i = 0; i < objectTags.length; i++) {
objectTagsArr[i] = objectTags[i];
}
for (i = 0; i < objectTagsArr.length; i++) {
var objectTag = objectTagsArr[i];
if(objectTag.data.indexOf('http://www.youtube.com/') >= 0) {
var youtubeID = objectTag.data.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^'&?\/ ]{11})/i)[1];
var newIframeElem = document.createElement('iframe');
newIframeElem.class = 'youtube-player';
newIframeElem.type = 'text/html';
newIframeElem.width = 640;
newIframeElem.height = 385;
newIframeElem.src = 'http://www.youtube.com/embed/'+youtubeID;
newIframeElem.frameborder = 0;
objectTag.parentNode.replaceChild(newIframeElem, objectTag);
}
}
})();