javascript没有在webview中为vimeo视频运行

时间:2012-08-21 09:44:20

标签: javascript html5 uiwebview vimeo

我有一个名为htmlString的字符串,我放置了我的iframe和javascript.But不知怎的,我的javascript没有运行。我已经使用loadHTMLString来加载html.Need来找出问题所在

NSString *htmlString = [NSString stringWithFormat:

                                @"<html><head><meta name = \"viewport\"content = \"initial-scale = 1.0, user-scalable = no\"/><script type=\"text/javascript\">"
                                @"alert (\"hello1\")"
                                @"function ready() {"
                                    // Keep a reference to Froogaloop for this player
                                @"var player = $f(player),"
                                @"$fplayer.api('play');}"

                                @"window.addEventListener('load', function() {"
                                @"alert (\"hello\")"
                                @"                                               $f(player).addEvent('ready', ready);"
                                @"                                           });"


                                @" </script></head><body><iframe id=\"player\" src=\"http://player.vimeo.com/video/8118831?api=1&amp;player_id=player\" width=\"320\" height=\"480\" frameborder=\"0\" webkitallowfullscreen allowfullscreen></iframe>"
                                @"</body></html>",@"http://www.vimeo.com/8118831"
                              ];

1 个答案:

答案 0 :(得分:0)

基本上你必须从Github导入froogaloop.js。然后使用以下

NSString *htmlString = [NSString stringWithFormat:@"  <html><head><script src=\"froogaloop.js\"></script><script>function ready() {$f(document.getElementById(\"player\")).api(\"play\");}function func1() {$f(document.getElementById(\"player\")).addEvent(\"ready\", ready);}window.onload=func1;</script></head><body><iframe id=\"player\" src=\"http://player.vimeo.com/video/39287488?api=1&amp;player_id=player\" width=\"320\" height=\"480\" frameborder=\"0\"></iframe></body></html>"];

还要确保使用UiWebViewDelegate