Javascript 断帧检测
我需要一些方法来检测某个URL中的站点是否为framebreaker。我的意思是,Framebreaker-如果它加载到一个框架中,它会阻止框架结构的站点。不知道为什么要将其标记为php,只有javascript可以这样做Javascript 断帧检测,javascript,html,frame,Javascript,Html,Frame,我需要一些方法来检测某个URL中的站点是否为framebreaker。我的意思是,Framebreaker-如果它加载到一个框架中,它会阻止框架结构的站点。不知道为什么要将其标记为php,只有javascript可以这样做 if (top !== window) { top.location.href = '/url/'; } 如果您问的是“如何防止在框架中查看我的网页?”那么以下是: 使用CSS将页面正文设置为不显示: <style> body { display :
if (top !== window) {
top.location.href = '/url/';
}
如果您问的是“如何防止在框架中查看我的网页?”那么以下是: 使用CSS将页面正文设置为不显示:
<style>
body { display : none ; }
</style>
正文{显示:无;}
然后,仅当页面不在框架中时才显示该页面:
<script>
if (self == top) {
//Not in a frame
document.getElementsByTagName("body")[0].style.display = 'block';
} else {
//In a frame. Redirect to the real page.
top.location = self.location;
}
</script>
if(self==顶部){
//不在框架内
document.getElementsByTagName(“正文”)[0].style.display='block';
}否则{
//在一个框架中。重定向到真实页面。
top.location=self.location;
}
将样式放在中,将脚本放在中
如果您只想检测页面是否正在被框架化,而不想对此做任何事情,那么您只需要以下javascript:
<script>
if(self == top) {
alert("Not in a frame");
} else {
alert("In a frame");
}
</script>
if(self==顶部){
警报(“不在框架内”);
}否则{
警报(“在一帧中”);
}
我需要检测站点是否为Framebreaker,然后对此发出警报。标记已删除,谢谢。这是一个framebreaker脚本而不是预防,我如何预防framebreaker?Yu已将此问答关系标记为已解决Ôo