0

我有一个名为htmlString我放置 iframe 和 javascript 的字符串。但不知何故,我的 javascript 没有运行。然后我用来loadHTMLString加载 html。需要找出问题所在。

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"
                              ];
4

1 回答 1

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它。

于 2012-08-21T13:44:05.420 回答