【问题标题】:Redirecting iframes no different url重定向 iframe 没有不同的 url
【发布时间】:2018-01-31 10:17:09
【问题描述】:

随机购买了一个 .com 域,而我拥有 .net。他在链接到我的网站上发布了一个 iframe,并且在顶部是否发布了“该网站正在出售”,我需要阻止这种情况发生。是否可以使用 PHP 或 javascript 来阻止该特定网站访问我的网站,或将他的 iframe 重定向到其他地方。

【问题讨论】:

    标签: iframe external


    【解决方案1】:

    这很简单: 假设他以这种方式使用您的文件

    a.html

    <html>
        <body>
            <iframe src="sample.html"/>
    </html>
    

    只需将以下行添加到您已经存在的文档加载函数中:

    window.onload = function(e) {
        if ( window.self !== window.top ) {
        //Your site is in i frame
        //just redirect to his own site if you feel like there will be an endless recursion so nothing will load probably.
        //You can put your custom action if this is not what you want
            window.self.location = "a.html"
        //would be pretty good enough :D
        }
    };
    

    【讨论】:

      猜你喜欢
      • 2014-12-02
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2013-04-30
      相关资源
      最近更新 更多