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 50megs.com), 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(allEles[i].style["visibility"]!=undefined)
{
if (isDel(allEles[i])==true)
{
allEles[i].style["visibility"]="hidden";
}
}
}
var w = document.body.clientWidth;
w=(w-685)/2;
var ele = document.getElementById("keepThis");
ele.style['left'] = w;
}
function isDel(ele)
{
var rtn = true;
if((ele.nodeName==undefined)||(ele.nodeName==undefined)||(ele.id==undefined))
return false;

if((ele.nodeName.toUpperCase()=="BODY")||(ele.nodeName.toUpperCase()=="HTML")||(ele.nodeName.toUpperCase()=="HEAD")||(ele.nodeName.toUpperCase()=="SCRIPT")||(ele.nodeName.toUpperCase()=="META"))
return false;

while(ele)
{
if (ele.id=="keepThis")
{
rtn=false;
break;
}
if (ele.nodeName!=undefined)
ele=ele.parentNode;
else
break;
}
return rtn;
}


</script>



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

8 comments:

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 50megs.com 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 www.bogra.i8.com

Dhanushka said...

http://www.upasaka.5u.com, 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,
Taoto

Mohamed said...

Dhanushka its gr8 but It is wrong in ethically and morally