Helping Geeks Win the War on Technology Since 2010

Simple Javascript Frame Breaker Code for Google Images et al

February 3, 2011

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.

posted in Javascript by helpgeek

Follow comments via the RSS Feed | Leave a comment | Trackback URL

6 Comments to "Simple Javascript Frame Breaker Code for Google Images et al"

  1. Keiron Waites wrote:

    Have you verified that this actually works with Google Images?

  2. helpgeek wrote:

    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.

  3. 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 [...]

  4. Karen wrote:

    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!

  5. helpgeek wrote:

    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.

  6. Active Reader wrote:

    Does not work with newer versions of Chrome and Firefox beta.

Leave Your Comment

 
Powered by Wordpress and MySQL on MDDHosting. Theme by Shlomi Noach, openark.org