How to prevent sites from loading your site in a frame?

Question

Today i received an email regarding “How can i prevent my website load from a frame“? He keep complaints about others site load his website into a frame and pretend the content is their own website. He asking about whether i have a solution for him?

Solution

Yes, We can prevent it by a simple Javascript code. Please copy and paste following code into your body of HTML code.


<SCRIPT LANGUAGE="JavaScript">
if (window != top) top.location.href = location.href;
</SCRIPT>

Above Javascript will detect whether your website is load through frame. If yes, it will redirect it to your website. Hope it help. :)

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Bas Recent comment authors
newest oldest most voted
Bas
Guest
Bas

And what if the guys load your site in an image tag ;-)