【问题标题】:Blocked a frame with origin "https://www.youtube.com" from accessing a frame with origin "file://"阻止来源为“https://www.youtube.com”的框架访问来源为“file://”的框架
【发布时间】:2015-07-29 21:41:17
【问题描述】:

我有一个 youtube 的网址:

<iframe class="embed-responsive-item" ng-src="https://www.youtube.com/embed/s7gJ74ARN84" allowfullscreen=""></iframe>

如果我在我的本地 html 文件中使用它,它会运行良好。但是,当我将相同内容粘贴到 phonegap ios app html 页面并在 ios 模拟器中运行时,它会在我单击视频时显示以下错误:

Blocked a frame with origin "https://www.youtube.com" from accessing a frame with origin "file://".  

The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "file". Protocols must match.

解决方案:

它不是在模拟器中工作,而是在移动设备中工作,这是我的最终目标。

【问题讨论】:

    标签: cordova iframe youtube youtube-api youtube-iframe-api


    【解决方案1】:

    @Manish,

    您似乎遇到了CORS 问题。您可以添加到您的config.xml &lt;access origin="*"/&gt;

    杰西

    【讨论】:

    • 这似乎没有帮助(至少在 iOS 9.3、cordova 6.4.0、cordova-plugin-whitelist 1.3.0 中)
    【解决方案2】:

    确保你已经安装了cordova-plugin-whitelist

    并在 config.xml 上添加这一行

    <!-- Whitelist the domain -->
    <allow-navigation href="https://*youtube.com/*"/>
    

    如果您想将所有 URL 的访问列入白名单,您可能需要使用此功能
    但是如果你的应用程序可以被脚本注入,你必须小心,这将是一个安全漏洞

    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    

    【讨论】:

      【解决方案3】:

      @马尼什, 由于您已经处理了 CORS 问题,因此您得到的错误是:

      请求访问的帧具有“https”协议,该帧是 访问具有“文件”协议。协议必须匹配。

      既然不是CORS,那你有没有去掉iframe?如果可行,也许您需要的是隐藏的&lt;div&gt;

      杰西

      【讨论】:

      • 我没明白你的意思,你可以举个例子参考我的 youtube 视频
      【解决方案4】:

      嘿,这只是一个很小的问题

      你的链接是这个 => "https://www.youtube.com/embed/s7gJ74ARN84"

      但你只需要把它改成

      此链接“//www.youtube.com/embed/s7gJ74ARN84”

      请记住,当您尝试在您的网站中加载安全内容时,只需从链接中删除协议

      【讨论】:

      • 试过这个&lt;iframe width="854" height="510" src="//www.youtube.com/embed/bAQq2mENhR4" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;并得到这个错误Failed to load resource: The requested URL was not found on this server. file://www.youtube.com/embed/bAQq2mENhR4
      • 在 jsfiddle 中甚至 &lt;iframe width="854" height="510" src="http://www.youtube.com/embed/bAQq2mENhR4" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt; 工作正常
      • 问题是在 IOS 模拟器中它没有运行,但在移动设备中它正在运行,这是我的最终目标 :)
      • 这不是因为它自动匹配协议吗?所以//url.com 将是file://url.com 如果原始页面是file://index.html
      猜你喜欢
      • 2015-06-28
      • 2013-10-14
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2016-09-28
      • 2013-09-19
      • 1970-01-01
      相关资源
      最近更新 更多