I use this javascript in a UIWebvView to get the URL of a YouTube video.
getURL = [self.webView stringByEvaluatingJavaScriptFromString:@"function getURL() {
var player = document.getElementById('player');
var video = player.getElementsByTagName('video')[0];
return video.getAttribute('src');
}
getURL();"
];
It works fine on iPhone, but fails on ipad and returns @””. Both devices load the m.youtube.com website. Could anybody help me?
The iPad and the iPhone have different HTTP header information, specifically the user agent string. It is possible that YouTube is sending down different javascript depending on which device the user has.
You might try overriding the “user agent” HTTP Header in your request. I think this Stack Overflow answer may work for that: Change user agent on UIWebView
If not, you might try using a set of third party classes like AISHTTPRequest to spoof the user agent information to access the youtube URL from the iPad while making YouTube think it is an iPhone.