如果网站未显示在框架中,则重定向

2by*_*2by 1 php .htaccess redirect

我有一个页面我只希望在iframe中显示时可见.

这可能在PHP,htaccess或其他什么?怎么样?

我更喜欢PHP的解决方案

谢谢!

Cfr*_*eak 8

框架只是客户端,因此您无法通过PHP或.htaccess进行检查.你可以在Javascript中查看它.看到这个帖子:

如何识别网页是在iframe中加载还是直接加载到浏览器窗口?

编辑 这是一个可以重定向的示例.它是直接的Javascript,但如果你使用jQuery这样做,你可以编写相同的功能document.ready

<script>
function check_frame() {
     if( top === self ) { // not in a frame
          location.href = "/link/to/some/url"; // either the frameset or an error.
     }
}
</script>
<body onLoad="check_frame()">
... normal code for your page here ...
</body>
Run Code Online (Sandbox Code Playgroud)

请注意,页面仍然可以是PHP页面,它只需要输出那一点Javascript.