【发布时间】:2018-01-31 10:17:09
【问题描述】:
随机购买了一个 .com 域,而我拥有 .net。他在链接到我的网站上发布了一个 iframe,并且在顶部是否发布了“该网站正在出售”,我需要阻止这种情况发生。是否可以使用 PHP 或 javascript 来阻止该特定网站访问我的网站,或将他的 iframe 重定向到其他地方。
【问题讨论】:
随机购买了一个 .com 域,而我拥有 .net。他在链接到我的网站上发布了一个 iframe,并且在顶部是否发布了“该网站正在出售”,我需要阻止这种情况发生。是否可以使用 PHP 或 javascript 来阻止该特定网站访问我的网站,或将他的 iframe 重定向到其他地方。
【问题讨论】:
这很简单: 假设他以这种方式使用您的文件
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
}
};
【讨论】: