我在一个页面中嵌入了一个YouTube视频,并有一个滑块,我可以使用该滑块设置播放器速度.
我在用 player.setPlaybackRate(value);
问题是我希望范围从0.5到3,但播放器API仅将值限制为预定义[0.25, 0.5, 1, 1.25, 1.5, 2]
.
在YouTube中我可以轻松调整速度document.getElementsByTagName("video")[0].playbackRate = 3
但在iframe上我没有这样的访问权限.
我有一个沙盒iframe,不允许更改位置:
<iframe sandbox="allow-forms allow-popups allow-pointer-lock allow-same-origin allow-scripts" class="iframe visible" src="thesource.html" width="100%" scrolling="auto" frameborder="0"></iframe>
Run Code Online (Sandbox Code Playgroud)
如果iframe尝试取消框架本身或更改位置,我会看到一个空白页面,因为浏览器会停止iframe的操作.这是来自Chrome的日志:
不安全的JavaScript尝试从URL为" http://otherdomaian.com "的框架启动URL为" http://example.com "的框架导航.尝试导航顶层窗口的框架是沙箱,但未设置"允许顶部导航"标记.
这很好,但我想抓住这个,如果它发生,我会转移到下一个iframe.那我怎么抓住这个尝试呢?
编辑:
我添加了一个jsfiddle代码(检查控制台日志中的错误)
我也试着听一个没有成功的事件:
document.addEventListener('error', receiveMessage, true);
function receiveMessage(error) {
alert("iframe tried to unframe itself");
}
Run Code Online (Sandbox Code Playgroud)