Coffee CupQuite a lot of sites have an annoying habit of forwarding to your site but maintaining a smidgen of control by leaving a controlling banner at the top of your page, either advertising their services or worst of all, displaying an actual advert and thereby gaining some revenue out of your content.

Not cool. Examples of what I’m talking about? Well click through to a blog from Afrigator’s main site, or from a blog roll on any blog using the BlogRolling blog roll service and you’ll see what I mean. (Unfortunately this does also then include the more useful users of top banner controls like Google Images or even Bing’s Image Search. That said, you can always do checks for these and exclude them from your banner removing script.)

The actual Javascript code to detect and remove these banners is blindingly simple:

if (top.location != self.location) { top.location = self.location; }

Placing it in the head of your page or perhaps in the $(document).ready function if you are using jQuery, this quick check will essentially ensure that offending frame is quickly and easily broken out of.

For the CodeUnit blog I’m adding in a quick Growl notification (using the excellent jQuery BlockUI add-on) just to let users know what is going on, before they have a hissy fit with all this jumping about.

$(document).ready(function() {
//removes any nasty banner ads that might be displaying themselves!
if (top.location != self.location) {
$.growlUI('Tomfoolery Detected', 'Working to remove unwelcome banner frame as we speak...');
top.location = self.location;

To see it in action, click here.