Pregunta

¿Cuál es la mejor manera de eliminar un marco de página automáticamente?

He usado este tipo de código antes:

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

Solución

¿Quieres decir si alguien ha puesto un marco alrededor de tu contenido? Si es así, necesita lo siguiente en cualquier lugar de su página HTML para saltar fuera del iframe:

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

Otros consejos

Aquí hay una alternativa que es más genérica, ya que no nombra la URL principal ni utiliza la llamada a la función por separado:

// 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    
}

Hágalo de esta manera si desea que el paso para romper el marco no aparezca en el historial

if ( self.location !== top.location )
{
    top.location.replace( self.location );
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top