How To Prevent Others From Loading Your Page In A Frame

Last month, I found out that someone was loading one of my pages in his website using a frame. Whenever the website is loaded, my page will appear as if it was the owner’s. I do not know what this person is trying to do or gain from it but I found a method to defeat it.

There is an article at Web Developers Notes on how to prevent web pages from loading in frames. You only need to insert the javascript code below in the HEAD section of the document that you would like to protect.

if (self != top)
   top.location.href = self.location;href;

How does it work?

The paragraph below is quoted from the article. It explains how and what the code does.

The code tests whether the top page is the same as the page being displayed. If this is not the case, the URL of the top page is changed to the URL of the present page. Thus, your page always loads in a full browser window the way you wanted it.


I have tried it out and it works like a charm. Try clicking here to check out the previous website that was loading my page in a frame. Now, the page redirects to my original page. Notice the URL at the top of the page shows it is loaded from my blog.

If you want to prevent others from loading any of your pages in a frame, use the code provided above.

5 thoughts on “How To Prevent Others From Loading Your Page In A Frame

  1. TenthOfMarch says:

    I tested and it works.

    1) HideMyAss (web proxy): Click here.
    1) Google translation: Click here.

    @Hasbullah Pit
    What you are doing is different from the situation I mentioned in my post, so it is ok. This post is to prevent people from loading the entire web page as a frame. Yours only take roughly a paragraph and a link, which is not too bad.

    Yours works like an aggregator. However, there may be some people who do not like it though. Depends on individual bloggers.

  2. Hasbullah Pit says:


    you visit the page after modification.
    before this i use “rss2html” to display the content, and the page were actually embed inside frame.

    Then i use RSSinlude, it load page in new window. 🙂

    I actually want to give free link for my visitor without having much of static link in the blog page.

    Yeah I know some people may not like it. They may request from me to remove their site.

  3. TenthOfMarch says:

    @Hasbullah Pit
    Oh, ic. Sorry that I didn’t get to see the page before the mod. Back to the question on how to load a new page in new window:


Leave a Reply

Your email address will not be published. Required fields are marked *