Wednesday, August 8, 2007

How to remove all adds put in a free web hosting site using a simple JavaScript

All sites that hosts web sites for free (Such as, puts their adds on our html pages. So what can we do for avoid these adds. In one side you can by a hosting plan paying money. But I am going to tell you the other way. That is hide all the adds that were not put by us.
To do second method, first you should create your site inside a div tag which has id of "keepThis" as following

<div id="keepThis">Here put your code for the page</div>

Then you should put onLoad event on body tag as following..

<body background="../bg.jpg" onLoad="killAll()">

Then put following JavaScript to header section of your page.

<script language="JavaScript">

function handleError(msg,url,num)
return true;

window.onerror = handleError;

function killAll()
var allEles = document.getElementsByTagName('*');
for(var i=0; i {
if (isDel(allEles[i])==true)
var w = document.body.clientWidth;
var ele = document.getElementById("keepThis");['left'] = w;
function isDel(ele)
var rtn = true;
return false;

return false;

if ("keepThis")
if (ele.nodeName!=undefined)
return rtn;


Hey you're done now. You can host your page without any forced adds on a free web server.


Digital Writer said...

This is a good idea for newbies. Most of web masters face this problem in free hosting. Did you check all of major free hosting type web sites?

Dhanushka said...

Yes, I checked it with and it worked fine...

Graché said...

isn't it against the TOS for most free web hosts?

Dhanushka said...

May be, but they will take more time to detect it or it will be never detected. Since my site is still active with this script for more than one year I think this is a good way..

Anonymous said...

I try this code with my 50megs web site but it is not working. can you please what to do next. My web site

Dhanushka said..., I have used it here... It's working, see..

The Angel of the odd said...

Thank you very much.
It worked a treat!

Best regards,

Mohamed said...

Dhanushka its gr8 but It is wrong in ethically and morally