This is going to be short and simple tip. There are chances that your site can be put into iframe and you probably do not want that to happen. But javascript-digimantgrathere are not chances for your site to handle such situation, only before reading this post 😛

So how do you avoid that ? Well it is fairly simple using Javascript’s window object properties. Lemme first show you the code and then quickly explain it to you.

<script type="text/javascript">
   if(!=window.self)""; //replace the URL by ur site's URL

The property of window object return you the object of the top window from the DOM hierarchy of the page. However the window.self return you an object of the iframe in which your site is opened. The if condition matches both and if they are not equal, then it changes its location to your site, this is how you wanted 😛

Now if you want to see the actual URL, i mean if u are curious to know what the and window.self actually return, then you can use the following code.

<script type="text/javascript">

Hope that helps
Sachin Khosla

Share this post: