How to create script to break a web page out of a frame

Updated: 04/01/2018 by Computer Hope
break web page out of frames

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


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.

if (top.location != location) { top.location.href = location.href; }


Users who have JavaScript disabled are not 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="" target="_top">Break out of frame</a>

Additional information