This section contains the jQuery code that does the video-switching magic.
In order to use the following code you must already have jQuery loaded. To try this out yourself, you should also have a webpage with at least one Vimeo video embedded.
There two parts to this code – the first part, myGlobals, contains two properties: uaiphone and uaipad. Each of these properties checks the userAgent value of the user’s web browser and determines if it’s an iphone or an ipad. By using a shorthand conditional, we can return a boolean for each property, which we can use anywhere to test whether or not to execute special device-specific code later.
The second part is the code that actually finds and replaces the Vimeo flash player with an HTML5 video link. The code comments in the example should be enough of an explanation into how this works – but the core concept is that we extract key information from the object element and it’s children (video id and player size) and use it to create new, Flash-free, device-appropriate HTML. By wrapping this in jQuery’s ready event, we can execute the switch passively. In other words, we drop this code in our site-wide .js file, and it will automatically replace the Flash videos with HTML ones whenever they appear.
jQuery: Vimeo Mobile Embed Replacement Code
//Make some global variables
var myGlobals = {
//True if device is an iPhone
uaiphone: (navigator.userAgent.toLowerCase().indexOf('iphone')!='-1'),
//True if device is an iPad
uaipad: (navigator.userAgent.toLowerCase().indexOf('ipad')!='-1'),
//True if device is Android-based
uadroid: (navigator.userAgent.toLowerCase().indexOf('android')!='-1'),
}
//When dom is ready...
jQuery(function(){
//If this is an iphone, replace video object with this code...
if(myGlobals.uaiphone || myGlobals.uaipad || myGlobals.uadroid){
jQuery('object param[name="movie"]').each(function(){
//Find the Vimeo id of this video
var vidid = jQuery(this).attr('value').match(/clip_id=(\d*)\&/)[1];
//Get the width of the video
var vidwidth = jQuery(this).parent().attr('width');
//Get the height of the video
var vidheight = jQuery(this).parent().attr('height');
//Start with this empty, assuming full quality (for iPad)
var mobileQual = '';
//Set to mobile quality if on iPhone
if(myGlobals.uaiphone || myGlobals.uadroid){
mobileQual = '&quality=mobile';
}
//Create the replacement HTML5 code for the video
var vidlink = "";
//Insert the new HTML5 after the original video
jQuery(this).parent().after(vidlink);
//Remove the original Flash content
jQuery(this).parent().remove();
});
}
});
Note: This code may interfere with other, non-Vimeo flash videos that you embed on your site. It can also become very costly (in terms of performance) if you have a lot of videos on a single page, so use this code with that in mind.
If everything goes according to plan, then any Vimeo videos on your site should look like this when viewed on an i-device…

A Vimeo embed fixed for iPhone
Note that you do not get poster frames using this technique – just a generic gray video button/box. There are tricks you could use to make this look better (a little CSS, perhaps), but I’ll leave that part up to you. The good news is that your embedded Vimeo videos should now automatically adjust themselves for iPhone and iPad users (this could probably be adapted for Android devices as well – but since I don’t have one, I can’t really experiment with it).
2 Comments on (jQuery) Make Vimeo Embeds iPhone-friendly… Automagically!
First of all thanks for the code. This is exactly what I’m looking for. I’m developing a portfolio site for my company and am using embedded vimeo videos to make a gallery of video projects. I modified your code very slightly to act as a function that I can call once a video is loaded (because no vimeo videos are actually loaded at the beginning – they are created when the user clicks on a thumbnail). This worked (kind of). The little blue lego block that means “you can’t watch this video because it’s flash” is gone and has been replaced by a gray box with a quicktime logo in the bottom corner and the play button. However the play button is crossed out like a no smoking sign. Do you have any idea why this would be?
Thanks for the positive feedback. It’s nice to know that people find some of this stuff useful.
First, are you a Vimeo Plus member? I did a poor job of stressing this requirement in the above article (which I just updated to be clear on the issue), but you must be a Vimeo Plus member and you have to do these two things to your Vimeo settings for this work:
a) Enable “Generate Mobile Versions” from your account settings under Video Preferences (the option appears for Plus users only), then wait for the mobile versions to be encoded (can take up to a couple hours in my experience)
b) Set up your Video Privacy Settings to allow embedding
If you’re not a Plus member and don’t want to subscribe, you might try removing or commenting-out the mobile-quality-check part of the JavaScript code (lines 24-26 in the example above). This would theoretically force mobile devices to load the larger, full-quality versions of the video. I haven’t tested this workaround, but I don’t see a technical reason why it wouldn’t work (other than the files potentially being too large for a phone to handle).
Let me know if this helps.