Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果页面是iframe,则重定向_Javascript_Html_Redirect_Iframe_Get - Fatal编程技术网

Javascript 如果页面是iframe,则重定向

Javascript 如果页面是iframe,则重定向,javascript,html,redirect,iframe,get,Javascript,Html,Redirect,Iframe,Get,以下是我想做的: 在我的博客中,使用iframe在弹出窗口中显示评论。(例如:-对于第2篇文章,评论链接打开一个iframe fancyboxcomments.php?id=2) 我想检查comments.php是否加载到iframe中,如果没有,则重定向到相应的博客页面。i、 e.post.php?id=2 我查看了谷歌和其他网站,包括stackoverflow。但是没有用。请帮忙。(这似乎很容易。但它不起作用。我在想 if ( document.parent.frames.length &g

以下是我想做的:

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

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


我查看了谷歌和其他网站,包括stackoverflow。但是没有用。请帮忙。(这似乎很容易。但它不起作用。

我在想

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

应该可以工作

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

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

if(parent.location==位置){
location.href=“post.php”+location.search;
}

它不会将查询字符串传递到
post.php
,因此相关的帖子不会显示,但绝对不会。这是正确的。我把这部分留给了海报,想知道如何做。毕竟,边做边学是最好的学习方法之一。在我们的两个答案之间,我想他们能够拼凑出他们想要的答案寻找。我想每个人都有自己的想法。我只是想在可能的情况下提供一个完整的解决方案。