如果页面是iframe,则重定向

时间:2012-09-03 13:34:35

标签: javascript html redirect iframe get

这是我想要做的:

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

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

我查了谷歌和其他网站。堆栈溢出。但没用请帮助。 (这似乎很容易。但它不起作用http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/

2 个答案:

答案 0 :(得分:1)

将此脚本放入您的页面。如果未在框架中打开,则会重定向到post.php?id=...

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

答案 1 :(得分:0)

我在想像

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

应该有效

相关问题