views:

24

answers:

1
<html>
   <iframe src="iWantToBeTheParent.html" />
</html>

I think this is a JavaScript task, it would be nice to handle the redirection with htaccess though since my code will inside an iframe I'm looking for a method that initiates from inside the iframe source which would make the iframe url load as the parent.

I only have access to the iframe source page's html.
Would it be possible to send a 301 HTTP redirect as well?

EDIT: I could use php to print out the url of the iframe page as a JavaScript variable if needed.

A: 

You could try some javascript:

<script type="text/javascript">
    <!--
        if (top.location!= self.location) {
            top.location = self.location.href
        }
    //-->
</script>

Courtesy of: http://usablelayout.com/articles/automatically-break-out-iframe

This will set the top level location (the main page) to the location of the page where the javascript is located (inside the iframe).

Matt
Does anyone know if we can set HTTP Headers with JavaScript while doing the above redirect?
Mohammad