我的网页上有一个不是来自 youtube 或 vimeo 的嵌入视频。我希望观众只能观看我网页上的视频。如何防止点击视频时链接到另一个网页?我使用了 pointer-events: none 的 CSS 属性来阻止视频链接到另一个网页,但现在视频不会在我的网页上播放。请帮忙。
<!DOCTYPE html>
<html>
<head>
<style>
iframe {
pointer-events: none;
}
</style>
</head>
<body>
<iframe src="http://flashservice.simplevideo.com/embedframe/18598" frameborder=0 width=510 height=400 scrolling=no allowfullscreen ></iframe>
</body>
</html>
最佳答案
iFrame 的 sandbox
属性应该是您正在寻找的。
例如:
<iframe src="http://flashservice.simplevideo.com/embedframe/18598"
frameborder=0 width=510 height=400 scrolling=no allowfullscreen
sandbox="allow-same-origin allow-scripts"></iframe>
请注意,sandbox
属性充当白名单,因此不要为其提供 allow-popups
或 allow-top-navigation
权限,它不能打开新页面,也不能更改父网页!
关于html - 如何防止嵌入的视频链接到另一个网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473007/