【问题标题】:How to block my website from loading in other sites iframes如何阻止我的网站加载到其他网站 iframe
【发布时间】:2017-11-03 05:24:52
【问题描述】:

如何通过 iframe 阻止我的网站?例如,YouTube 不能出现在 iframe 中,它会说该网站的所有者已经阻止了 iframe。我知道这样的元标记方式

    <meta http-equiv="X-Frame-Options" content="deny"> 

howerver 对我不起作用,有没有其他方法,我更喜欢使用 javascript 和 html 没有 apachi php ajax 或其他请。这是我希望在我的网站上阻止的 youtube iframe。也没有.htaccess

   <!DOCTYPE html>
<html>
<head>
<title>YouTube</title>
</head>
<body>
<iframe width="50%" height="50%" src="http://www.youtube.com" >
</iframe>
</body>

【问题讨论】:

  • How to Block Iframe call的可能重复
  • 它不是重复的,我也不想要 .htaccess 方式。
  • This answer from that question 包括一个javascript解决方案!
  • @Hodrobond 这个问题的答案没有用,我的答案确实有效
  • @MohammadHamedani 这个问题的答案没有用,我的答案确实有效,而且......它不是重复的,我也不想要 .htaccess 方式。

标签: javascript php jquery html iframe


【解决方案1】:

我的解决方案是放入headbody 标签

<script type="text/javascript">
function PreventFrame() {
    try {
        if (window.top !== window.self) {
            document.write = "";
            window.top.location = window.self.location;
            setTimeout(function() {
                document.body.innerHTML = '';
            }, 0);
            window.self.onload = function() {
                document.body.innerHTML = '';
            };
        }
    } catch (err) {}
}
PreventFrame();
</script>

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 2013-11-19
    • 1970-01-01
    • 2016-11-27
    • 2023-03-12
    • 2019-04-18
    • 1970-01-01
    • 2021-07-08
    • 1970-01-01
    相关资源
    最近更新 更多