iframe页面可以告诉它们何时进行装帧吗? [英] Can iframe pages tell when they are iframed?

查看:226
本文介绍了iframe页面可以告诉它们何时进行装帧吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道,如果我将iFrame包含在不在同一域中的页面上,则无法通过浏览器策略访问该iframe的DOM,但是iframe中的页面可以执行任何形式的父文档访问?

So I know that if I include an iFrame to a page that is not on the same domain I can't access that iframe's DOM via browser policy, but can a page that is in an iframe do any kind of parent document accessing?

具体来说,我必须视这个问题而定:

Specifically I have to ideas that are contingent on this question:

  1. 如果嵌入式页面可以分辨出它不是父窗口,则可以使这两个站点都无法进行iframe的操作,这样,如果该页面检测到该页面是被iramed的,则该页面将变为"Go Away"页面或者,您可以将其设置为仅可iframe"(类似于仅用于包含页面的服务器端脚本),以便在不进行iframed时转到该页面将获得转到"页面.

  1. If the embedded page can tell that it is not the parent window, one could make either sites that are un-iframe-able so that if the page detects it is iframed it changes to a "Go Away" page OR you could make it only-iframe-able (similar to a server-side script for pages that are only meant to be includes), so that going to the page when it's not iframed would get a "Go Away" page.

如果iframed页面具有父窗口不具有的某些自由,则它可以请求父窗口的样式表并将其设置为样式表上的样式表,从而使该站点与父文档进行更多集成. (当然,然后,我可以使样式表与iframed网站更多相关,知道它将做到这一点,但我认为这不是问题).

If the iframed page has certain liberties that the parent window does not, it could request the stylesheet of the parent window and set it as its on stylesheet, thus making the site integrate more with the parent document. (Of course, then I could just make my stylesheet relate more to the iframed site, knowing it will do this, but I don't see that as an issue).

有人知道吗?

推荐答案

关于#1,是的,您可以使用一些简单的javascript来判断自己是否被陷害:

With regards to #1, yes, you can tell if you are being framed using some simple javascript:

<script type="text/javascript">
if (self != top)
{
  // Framed!
}
</script>

关于#2,我不确定您可以使用"top"变量做什么,但是我知道您可以更改其位置(因此,如果您的网站由另一个网站框起来,则可以更改框顶部框架的位置-本质上是将用户直接重定向到您的网站).

Regarding #2, I'm not sure what you can do using the "top" variable, but I do know that you can change it's location (so if your site is framed by another site, you can have your frame change the location of the top frame - essentially redirecting the user directly to your site).

不知道您对顶部框架还有什么可以做或不能做的,其他人可能可以在那里提供更多信息.

Not sure what else you can or can't do to the top frame though - someone else might be able to provide more information there.

这篇关于iframe页面可以告诉它们何时进行装帧吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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