Escaping forced IFRAME ads from your Webhost with JavaScript

Are you irritated by those forced advertisements placed through IFRAMEs on your free web space from your host? In this guide, I will show you how to escape the IFRAMEs used when masking / redirecting to your destination address.

These ads are displayed at the top of a forced IFRAME , with the main content being forwarded to the clients destination, all while remaining nested inside the parent frame so as to keep the main ad in the main frame on display through out the user’s entire browsing session.

Using the following JavaScript will help you get your content forwarded first, and then exit the forced ad’s by reloading itself without the IFRAME, thus no more IFRAME advertisements.

Network

The Guide

Installation

[code language="plain" line="1" autolinks="0"]

<!--//
if (self != top) if ( top.frames[1].name !="mainarea") top.location = "index.html";
//-->

[/code]

This script needs to be inserted between the HEAD tags in your HTML, before the closing HEAD tag. This ensures proper processing of the JavaScript in a timely manner.

The Logic

The basic login of this script is along the lines of this:

Check the very top frame’s name. If it’s name is not “mainarea”, then reload in the verytop frame the index.html file.

This will load relative to the forwarded location, so effectively if the site detects it is being loaded through an IFRAME that, with the IFRAME not being in the same location as the destination web page, it will force the browser to reload the file directly, rather than through the IFRAME. This, effectively allows the page to escape the forced IFRAME advertisement.

Happy IFRAME escaping!

Notes:

  • Compliance with your host’s policies: It is your responsibility to check your host’s terms of service and other legal documentation where available as to their policies regarding the escaping of such advertisements when using their services. Many companies providing free services will have such a policy in place so as to prohibit such advertisement exiting.
  • Implementing this script in your website’s setup: In this example, the web page which is reloaded without the frame is index.html . You may need to change this where appropriate, depending on the file’s name (extension, and main file name) which you wish to reload to.
  • Dependencies – Server: This script is specific to escaping IFRAMEs. If your content is not within an IFRAME this will not work as expected. It is common for advertisements to also be included through the “INCLUDES” function, either as an Apache-specific web server call, or as a PHP Includes call.
  • Dependencies – Client: This work-around utilizes JavaScript. JavaScript is executed after being loaded into your web-browser, rather than being executed on the server itself. For the JavaScript to execute as expected the end user must have JavaScript support in their web-browser, and have JavaScript support enabled or turned on. Generally all computer web browsers will have support for JavaScript. Occasionally some security-conscious computer users may disable the JavaScript support. Typically the only browsers which may not have JavaScript support will be the cheaper cell phones, which are not smart phones or PDA phones.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

*