如果页面是iframe,则重定向 [英] redirect if the page is iframe
问题描述
这是我想要做的:在我的博客中,
注释显示在 fancybox 使用iframe弹出。 (例如: - 对于帖子号2,评论链接打开一个iframe fancybox comments.php?id = 2
)
我想检查是否在iframe中加载了comments.php,如果没有,则重定向到相应的博客页面。即 post.php?id = 2
我检查了Google和其他网站。堆栈溢出。但没用。请帮助。 (这似乎很容易,但它不工作 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>
Here is what i want to do:
in my blog, comments are shown in a fancybox popup using iframe. (eg:- for the post number 2, comments link open an iframe fancybox comments.php?id=2
)
I want to check whether comments.php is loaded in an iframe and if not, redirect to the respective blog page. i.e. post.php?id=2
I checked Google and other sites incl. stackoverflow. but no use. pls help. (this seems to be easy. but it ain't working http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/
Put this script in your page. If it is not opened in a frame, it will redirect to post.php?id=...
<script type="text/javascript">
if (parent.location==location) {
location.href = "post.php" + location.search;
}
</script>
这篇关于如果页面是iframe,则重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!