[X]

Break Out Of Frames

navigation 1997 still works

Forces your page to the top window if somebody loads it inside their frameset.

In 2026: Still works and is still the right idea. The modern equivalent is the X-Frame-Options or frame-ancestors header, which a script cannot be talked out of.

Where it came from: Circulated widely from about 1997, once people started framing other people's sites.
MDN MDN frame-ancestors

<script language="JavaScript">
if (top.location != self.location) {
  top.location = self.location.href;
}
</script>

<p style="font:13px Verdana">This demo just tried to bust out of its frame. The
sandbox around it refused the navigation, which is the modern header doing for
every site what this script did for one page.</p>

<!-- The 2026 version. Send this as an HTTP response header instead: -->
<!-- Content-Security-Policy: frame-ancestors 'self' -->
sandboxed demo · breaks nothing but itselfrestart

More in navigation

view the whole library ›