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.