Rumah > hujung hadapan web > html tutorial > 网页被iframe了怎么办?

网页被iframe了怎么办?

小云云
Lepaskan: 2017-11-18 09:41:00
asal
2838 orang telah melayarinya

大家都知道一种功能叫“嵌套”,自己辛辛苦苦做出来的网站却被别人使用 iframe 给你套了个马甲就成了他的页面内容,也许你会很生气想去阻止,那么你应该怎么做才嫩而过组织网页被iframe呢?这里就介绍几种方法教你如何防止自己的网站,网页被别人 iframe 走了。

(1)第一种禁止页面被 iframe 的方法,在页面加入如下JS代码:

<script type="text/javascript">      
 if(top.window.location.href!=window.location.href){    
top.window.location.href=window.location.href;    
}    
</script>
Salin selepas log masuk

(2)第二种禁止页面被 iframe 的方法,在页面加入如下JS代码:

<script type="text/javascript">      
 if(top.location!=self.location){    
top.location=self.location;    
 }    
</script>
Salin selepas log masuk

据说这种解决方法在 Firefox 下面页面会一直不停的刷新,这里是因为在IE下windows.top是本窗口,而在 firefox 下面 windows.top如果没有那么就是空。 所以会不断的运行这段js代码这就造成了一个死循环,也就造成了页面一直在刷新。

(3)第三种禁止页面被 iframe 的方法,在页面加入如下JS代码:

<script type="text/javascript">      
 if(window!=parent){    
parent.navigate(window.location.href);    
 }    
</script>
Salin selepas log masuk

另外如果用 php 开发的 web 程序的话,也可以直接使用 php 来实现禁止页面被 iframe 的效果,在程序代码中加入:

 if($_server[&#39;http_host&#39;]!=&#39;www.phpernote.com&#39;){    
 exit(&#39;禁止iframe我的页面!囧&#39;);    
}
Salin selepas log masuk

asp 语言也有自己独特的禁止页面被 iframe 的实现代码,如下:

host=Request.ServerVariables("SERVER_NAME")    
if host<>"www.phpernote.com" then    
response.redirect "http://www.phpernote.com/"    
end if
Salin selepas log masuk

当然其它编程语言也都可以通过获取环境变量来实现防止页面被 iframe 的效果,这里就不一一举例了。

当你想阻止别人iframe你的网站或者网页时,那么不妨试试以上这种方法吧,希望能帮助到你。

相关推荐:

如何使用iframe属性

php表单文件中关于iframe如何异步上传的案例

如何避免网页被人嵌套在 iframe 里?

Atas ialah kandungan terperinci 网页被iframe了怎么办?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan