JavaScript To Stop Frames

27th May 2008 - 1 minute read time

The following section of JavaScript will detect if anyone is viewing your page in a frame. If they are then the code will redirect them to your site. It essentially stops people using frames to poach your content and stops online proxy software from viewing your site.

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

All you have to do is include this code either in your script tag or your JavaScript includes. Quite a neat little trick really.

Add new comment

The content of this field is kept private and will not be shown publicly.