views:

771

answers:

2

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?

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

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>    
Ciaran Bruen