Home Page : HTML and JavaScript : How to prevent being framed

www.cryer.co.uk
Brian Cryer's Web Resources

How to prevent a page from being framed

To prevent a page from being framed by another site, include the following:

<script type="text/javascript"><!--
if (self != top)
{
   if (document.images)
      top.location.replace(window.location.href);
   else
      top.location.href = window.location.href;
}
// --></script>

It would be wise to include this at the top of the file, preferably before any <body> html.

What this script does is to redirect the browser to your file if it is being shown within a frame.

This is useful if you believe that another site may be showing your page within a frame and you wish to prevent it.

A word of caution: if you use frames on your site then this JavaScript will prevent you from framing your own page and this may not be desirable.