Creating script to break web page out of frames

Updated: 04/26/2017 by Computer Hope

break web page out of framesUsing either of the examples below will automatically break a browser out of any frame that links to your page. Keep in mind that some web services such as services that translate your web page into another language may no longer work because of the need of a frame.

Note: Some services such as website translation and Google images may use frames to display your content. If you break out of the frames these services may also break.

Breaking out of frame using JavaScript

Place the below script in the <HEAD></HEAD> section of your HTML.

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

Note: Keep in mind that users who have JavaScript disabled will not be taken out of a frame using this method.

Alternatively if you want to create a link for users to break out of a frame on your website you can add the example below.

Breaking out of frame using a link

<A href="https://www.computerhope.com/" target="_top">Break out of frame</a>

Additional information

  • See our frame definition for further information and related links on this term.