admin管理员组

文章数量:1335871

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="";
}
</script>

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.";
}
</script>
Share Improve this question edited Aug 15, 2014 at 1:30 scarver2 7,9952 gold badges54 silver badges63 bronze badges asked Oct 15, 2008 at 14:46 KeltexKeltex 26.4k12 gold badges81 silver badges112 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

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>

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    
}

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 );
}

本文标签: javascriptHow do I automatically remove an HTML page frameStack Overflow