Iphone 视频元素与UIWebView的视频链接
我检查了Iphone 视频元素与UIWebView的视频链接,iphone,ios,objective-c,Iphone,Ios,Objective C,我检查了googlechrome中的YouTube页面,发现在playerdiv中有一个视频元素,其id为:player\u VIDEOID 我想从这个视频元素中获取src属性。 因此,我使用以下内容加载UIWebView: NSURL *url = [NSURL URLWithString:@"http://m.youtube.com/watch?v=bnVUHWCynig"]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:u
googlechrome
中的YouTube
页面,发现在player
div中有一个视频元素,其id为:player\u VIDEOID
我想从这个视频元素中获取src属性。
因此,我使用以下内容加载UIWebView:
NSURL *url = [NSURL URLWithString:@"http://m.youtube.com/watch?v=bnVUHWCynig"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[web loadRequest:requestObj];
在-(void)webviewdiffinishload:(UIWebView*)webView
我在javascript中实现了一个函数,该函数通过以下方式提取此src链接:
[web stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function myFunction() { "
"var videoele = document.getElementById('player_bnVUHWCynig');"
"var url = videoele.getAttribute('src');"
"return url;"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"];
NSString * t = [web stringByEvaluatingJavaScriptFromString:@"myFunction();"];
和t
始终等于空字符串
我尝试在Chrome
中运行这个JS
函数,url是视频元素中的src链接
我在这个方法中做错了什么???所有的引号“
中间是什么,你的字符串没有任何反斜杠?你的代码编译了吗?是的。我检查了google chromeDid中的javascript代码。你解决了这个问题吗?