Sid
Sid

Reputation: 1253

redirect if the page is iframe

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/

Upvotes: 0

Views: 2372

Answers (2)

Scott
Scott

Reputation: 21501

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>

Upvotes: 1

Sage
Sage

Reputation: 4937

I am thinking something like

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

should work

Upvotes: 0

Related Questions