views:

711

answers:

3

What's the best way to remove a page frame automatically?

I've used this type of code before:

<script language="JavaScript">
setTimeout ("changePage()", 3000);
function changePage() {
if (self.parent.frames.length != 0)
self.parent.location="http://www.example.com";
}
</script>
A: 

Do it this way if you want the frame-breaking step to not appear in the history

if ( self.location !== top.location )
{
    top.location.replace( self.location );
}
Peter Bailey
+1  A: 

Here's an alternative that's more generic in that it doesn't name the parent URL, nor use the separate function call:

// is the current page at the top of the browser window hierarchy?
if (top.location != self.location)  
{
    // it isn't, so force this page to be at 
    // the top of the hierarchy, in its own window
    top.location = self.location    
}
DOK
+2  A: 

Do you mean if someone has put a frame around your content? If so, you need the following any where in your HTML page to jump out of the iframe:

<script type="text/javascript">
if (window.top.location != window.location) {
  window.top.location = window.location;
}
</script>
Remy Sharp