Ritchie
Ritchie

Reputation: 535

Redirect user to parent page when iframe is accessed directly

I am using a jquery lightbox plugin (http://colorpowered.com/colorbox/) to load content using an iframe. The problem is when users access the page directly or via a search engine the page they are taken to is the iframe content itself and not the parent page which loads the iframe.

How can i redirect users who access the iframe directly to be taken to the original page that loads the iframe?

Upvotes: 1

Views: 4064

Answers (2)

Ciarán Bruen
Ciarán Bruen

Reputation: 5341

If I understand you correctly you need to determine if you're in an iframe or not, so this jQuery should work:

<script type="text/javascript">
$(document).ready(function() {
    if (top != self) {
            window.location = "page_with_iframe.htm";
    }
});
</script>    

Upvotes: 0

Marius
Marius

Reputation: 58931

if(window.top.location == window.location){
  window.location = "http://example.com/whatever/page/you/want/them/to/go/to.html";
}

Upvotes: 4

Related Questions