Home > Coding > How to avoid your page from being embedded in Frame or iFrame

How to avoid your page from being embedded in Frame or iFrame

February 14th, 2009

If you use Google Image Search, you would have probably noticed that when you click on a picture, a new page will be popped. This page contains two parts: above is some information provided by Google; and below is the original webpage, which is wrapped in a Frame. And at this time, the URL in the browser address bar is a Google URL instead of the original one.

And you, as a webmaster, can disable this kind of use, so that if your page is embedded in a Frame or iFrame, when that page is loaded, the browser will be automatically redirected to your original link. You can do it by just adding the following code between the “<head>” tags of your webpage:

  1. <script type="text/javascript">
  2. if (window!=top)
  3.     top.location.href = window.location.href;
  4. </script>

For example, if some one found an image of your website through Google Image Search, and when he/she clicks the image, the new page that is popped out will be your original page: no Google information on top of your content and the URL in the browser address bar is your URL instead of Google’s.

You may think it’s unnecessary. But it is. Because Frame (or iFrame) would sometimes cause your content being anonymously “borrowed” by another website, your site’s URL would not even be mentioned. These sites may even add ads around your content. Google is a responsible corporation, because it gives very obvious information telling people the original URL. But some websites would not.

Mr. One Coding

  1. No comments yet.
  1. No trackbacks yet.