【问题标题】:javascript not running in webview for vimeo videosjavascript 没有在 webview 中运行 vimeo 视频
【发布时间】:2012-08-21 09:44:20
【问题描述】:

我有一个名为 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"
                              ];

【问题讨论】:

    标签: javascript html uiwebview vimeo


    【解决方案1】:

    基本上你必须从 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

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      相关资源
      最近更新 更多