Preventing IFRAME embedding
Some contemptable fellows like to embed other people's pages in IFRAMES on their own sites and then either make money from adverts on the parent frame or pass off the content as their own. This can be detected and prevented by making use of Javascript cross-site scripting security. Simply paste the script below into your page. It tries to access the URL of the parent window. If the page is not being viewed in an IFRAME, then the function will return successfully. If it is in an IFRAME on a different domain, then it will throw a security exception that you can catch and do somthing evil with.
<script language="javascript">
// detect if some cheeky monkey has embedded us in an iframe
try
{
// get the location of the parent window
var p = window.parent.location;
var str = new String(p);
}
catch (e)
{
// cross site scripting isn't allowed, so we must be in an iframe on a different domain
// send them to the 'error' page:
window.location = 'http://www.youtube.com/watch?v=Yu_moia-oVI';
}
</script>
Click here to see a test page embedded in an IFRAME.