javascript - 在 iFrame 中引用时,“deviceorientation”不会在 iOS 浏览器中触发

标签 javascript html ios iframe

我正在制作一个在 iframe 中运行“360 度全景查看器”的网站,其中源页面使用 JavaScript 和 window.DeviceOrientationEvent 来确定用户是否使用具有方向功能的移动设备。我在 iOS Safari 和 Chrome 上看到一些奇怪的行为:

window.DeviceOrientationEvent evaluates to true, but deviceorientation event is never triggered.

Android Chrome 不是这种情况 - 当在 iFrame 中使用时,事件会按预期连续触发。

直接访问页面(在 iOS 上)时,我看到事件触发。就好像在 iframe 中使用它以某种方式“阻止”了这个事件。

这对我来说意义不大,研究它揭示的信息很少,除了一些模糊的迹象 [1, 2] 它实际上可能与 CORS 有关 - 无论 iframe 源是否与 iframe 源位于同一根域父页面。这对我来说更没有意义..

有人知道吗?

1 2

最佳答案

对于现在遇到这个问题的任何人来说,Apple 似乎从 iOS 12.2 开始就禁用了 deviceorientation API。用户现在需要在 Settings > Safari > Motion and Orientation access 中明确切换它。参见 here供讨论。

关于javascript - 在 iFrame 中引用时,“deviceorientation”不会在 iOS 浏览器中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37262953/

相关文章:

javascript - Axios for Vue 未将图像上传到服务器

jquery - 多个粘性元素 Jquery Sticky Float

c# - NSUrl 请求在 Xamarin Today Widget 中不起作用

ios - iPhone 4s可以连接两个蓝牙4.0设备吗?

javascript - Webpack 包 - Bootstrap 的 JavaScript 需要 jQuery

javascript - Gatsby 没有在生产中加载 useEffect 函数

javascript - 如何在点击其他图像时更改div的图像

html - <input type ="file"> 在 Firefox 中显示第一个 "All Files (*.*)"而不是特定文件类型

javascript - 如何在 React 中将 html 表格单元格数据动态插入到具有动态标题的表格中?

iOS5 "Discarding message for event 0 because of too many unprocessed messages"是什么意思?