Categories
JavaScript

Detect if site in iframe and redirect

Quick and nasty fix to avoid your site been inside an iframe.

What we will do is to detect if we are in the same DOM window and if they are not we will redirect the top window to the location of your site (window).

Better see the code in javascript

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

Works on firefox and chrome. Based on this answer.