我在 000webhost 网站上创建了一个视频嵌入页面,然后它将嵌入到我在 Blogger 上运行的其他网站中。我不希望任何人直接访问 000webhost 视频页面或嵌入除我的博客网站之外的其他网站。我知道在内容安全策略、x-frame-options、.htaccess 的帮助下这是可能的。 但是它们都有局限性,比如有些不能在 chrome 和 Firefox 中工作,有些需要服务器端配置等......
例如,这是内容安全策略-
X-Frame-Options: Allow-From http://example.com
那么这种情况有突破口吗?
尝试使用 .htaccess
order deny,allow
deny from all
allow from mysite.com
内容安全政策
Content-Security-Policy: frame-ancestors 'self' http://example.com
编辑:尝试了 JavaScript 代码但没有按预期工作。当直接访问 000webhost 视频页面时,它将重定向到博客页面,但在框架中时它不会重定向
<script>
if (top.location.host != "https://example.com") {
window.location.href='https://example.com/bloggerdomain';
}
</script>
X-Frame-Options 中的 ALLOW-FROM 选项支持有限,现在 IE 消失了,几乎不再支持它了。
Content-Security-Policy:如果您将 frame-ancestors 放在带有 .htaccess 的响应标头中,它应该可以工作。它不会在元标记中工作。