For certain reasons, you may want to protect your website from being framed by another website. This is important if you are concerned that another website could take credit for your work like Google Images does in its image search.
Any image traffic you get from Google does not actually have to surf to your website, instead users can conveniently grab your images straight from the image preview pop up in Google Images search. They have to actually close the picture to view your website in its entirety.
It’s time to take control back. You may be missing out on that web traffic. If this is unacceptable for your needs, then adding a simple Javascript frame breaker code to your website can prevent this from happening.
Add this code somewhere in between your <head> tags in your website’s HTML code:
<script type="text/javascript">
<!--
if (parent.frames.length > 0) {parent.location.href = location.href;}
-->
</script>
What this small piece of code does is check if there is a parent frame, meaning your website has been put in a frame by another website. If it has, you simply change the parent frame’s URL to your websites URL. It’s that easy.


Have you verified that this actually works with Google Images?
Link | April 14th, 2011 at 12:18 am
I put this code on a website that had tons of images indexed by Google Images and all my pictures still showed up on image search. This Javascript code will work without affecting your indexed images or cause you to be deindexed or not indexed at all. Same with Bing Images, no negative effects.
Link | May 5th, 2011 at 11:14 pm
Javascript Iframe Breaker Code | Geek Help Guide wrote:
[...] Recent Posts Javascript Iframe Breaker CodeStyling WordPress Pages as Inline List without CSSAndroid Saving Persistent Data Between Application SessionsAndroid Function to Fetch HTML Page from Any URLWhy No Comments Are Showing on isoHuntHide or Disable the Admin Bar in WordPress 3.1Fix Blank Admin Nav Bar in Theme on WordPress 3.1Adding www to WordPress 3.0+ Multisite/MU Root DomainRemove DOS ^M Line Endings in VimCityVille Cheat: Boost Build Layout Adds +131%!MySQL String Search and Replace QueryFix iTunes 10.1.2 Stuck Install/Uninstall Hanging Near CompletionRecursively Search and Replace Strings in Linux with PerlHow to Get the Latest PeerGuardian Blocklists for P2PHow to Send Ctrl-Alt-Delete over Remote Desktop Protocol (RDP)Simple Javascript Frame Breaker Code for Google Images et al [...]
Link | May 5th, 2011 at 11:28 pm
Hi,
Do you still stand by your position that adding the framebreaking code will not effect the Google Image Search results for you images? I’ve tried this with three variations of the code you’ve given, and each one has had a negative effect on image placement in Google image search. Granted, I’ve only been testing for a week. Just wondering if you still think this code works. Thanks!
Link | November 11th, 2011 at 12:54 pm
I’ve not noticed any negative effects and continue to receive traffic for images. One week is really too short to test out a change, try for longer and see. Sometimes a site-wide change (like switching a WP theme) can cause a slight dip before recovering or improving rankings.
Link | November 22nd, 2011 at 7:55 am
Does not work with newer versions of Chrome and Firefox beta.
Link | December 20th, 2011 at 11:04 am