如何判断当前帧是否是父级? [英] How to tell if current frame is parent?

查看:117
本文介绍了如何判断当前帧是否是父级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个框架环境中工作,试图判断一些JavaScript代码执行的框架是否是顶框架(包含其余部分的框架)。



直到现在,我试图用

  window.parent!= null 

但它总是返回false,就像这个简单的例子一样。

 < HTML> 
< head>
< script>
alert(parent == null);
< / script>
< / head>

< body>
< h1> OH YEAH!< / h1>
< / body>
< / html>

有没有办法做到这一点?我不需要携带,现在我正在寻找IE6解决方案。 非常有用:
http://seclab.stanford.edu/websec/

总之,如果这段时间太长,那么他们最终会提出这样的建议:

< style>
html {display:none; }
< / style>
< script>
if(self == top){
document.documentElement.style.display ='block';
} else {
top.location = self.location;
}
< / script>

你会在这个pdf中找到许多其他方法来做到这一点,
显然,在没有JavaScript的浏览器上,这个解决方案可能很痛苦;)

I'm working in a framed environment, and trying to tell if the frame on which some javascript code executes is the top frame (the one that contains the rest).

Up until now I was trying to check it with

window.parent != null

but it always returns false, like in this simple example.

<html>
<head>
  <script>
    alert(parent == null);
  </script>
</head>

<body>
  <h1>OH YEAH!</h1>
</body>
</html>

Is there a way to do this? I doesn't have to be portable, right now I'm looking for the IE6 solution.

解决方案

I found this pdf to be very useful: http://seclab.stanford.edu/websec/framebusting/framebust.pdf

In short, if this is too long to read, this is what they ultimately propose :

<style>
  html { display :none; }
</style>
<script>
if(self==top){
  document.documentElement.style.display = 'block';
}else{
top.location=self.location;
}
</script>

You will find many other means to do this in this pdf and each means' pro and cons. Obviously, on browsers without JavaScript, this solution could be painful ;)

这篇关于如何判断当前帧是否是父级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆