如果页面为iframe,则重定向

redirect if the page is iframe

本文关键字:重定向 iframe 如果      更新时间:2023-09-26

以下是我想要做的:

在我的博客中,评论显示在使用iframe的fancybox弹出窗口中。(例如:-对于第2个帖子,评论链接打开iframe粉丝盒comments.php?id=2

我想检查comments.php是否加载在iframe中,如果没有,则重定向到相应的博客页面。即post.php?id=2

我查看了谷歌和其他网站,包括stackoverflow。但没有用。请帮忙。(这看起来很容易,但不起作用http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/

将此脚本放入页面中。如果它没有在一个帧中打开,它将重定向到post.php?id=...

<script type="text/javascript">
    if (parent.location==location) {
        location.href = "post.php" + location.search;
    }
</script>

我在想类似的东西

if ( document.parent.frames.length > 0 ) {
    document.parent.location = "post.php";
}

应该工作