用于清除页面广告的代码

<script language="javascript">
/* * * * * * * * *

函数名称:objAdCleaner

入口参数:不固定,见调用说明

返回值:无

功能:清除object(即flash)、link和script形式的广告代码。

调用说明:

有2种调用方式:无参数、参数列表

1)无参数:此方式下清除所有非本站的广告;

2)参数列表:此种方式需传入多个广告站点判别字符串(如:域名),以逗号分隔。

* * * * * * * * */
function objAdCleaner(){
 var iClearType=0;
 var aAdHost;
 var sMyHost=document.location.hostname;
 if(arguments.length==0){
  if(this.sMyHost=="" || this.sMyHost==undefined){
   this.iClearType=0;
  }else{
   this.iClearType=1;
  }
 }else{
  this.aAdHost=new Array();
  for(var i=0;i<arguments.length;i++){
   this.aAdHost.push(arguments[i].toString().toUpperCase() );
  }
  this.iClearType=2;
 }
 
 this.removeAllADs=function(){
  for(i = document.all.length-1; i >=0; i--){
   var ele=document.all(i);
   var elt=ele.tagName.toUpperCase();
   elt=="OBJECT"&& this.testAndDelete(ele,"data");
   elt=="SCRIPT"&& this.testAndDelete(ele,"src");
   elt=="A"&& this.testAndDelete(ele,"href");
  }
 }
 this.isAdTest=function(url){
  var rst=false;
  if(this.iClearType==1){
   rst=( url.toUpperCase().indexOf( this.sMyHost.toUpperCase() )<0);
  }
  if(this.iClearType==2){
   for(var i=0;i<this.aAdHost.length;i++){
    if( url.toUpperCase().indexOf( this.aAdHost[i] )>=0){
     rst=true;
     break;
    }
   }
  }
  return rst;
 }
 this.testAndDelete=function(oNode,sAttribute){
  if(this.isAdTest(oNode[sAttribute])){
   try{
    oNode.removeNode(true);
   }catch(e){}
  }
  return false;
 }
 this.removeAllADs();
}
</script>
<BODY οnlοad="objAdCleaner('ad.yieldmanager.com','optimizedby.rmxads.com','content.yieldmanager.edgesuite.net');">

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值