最近发现(20220年07月)使用UC浏览器,访问手机版网站的时候,出现了一些垃圾广告,而广告的内容,并非网站主动提供,是UC在没有经过站长同意的情况下添加的,以下代码可以有效防止自动添加广告代码,经测试有效,如果有疑问可以联系我们。
手机网站禁止UC广告代码
	
//清除UC手机浏览器强制代码
function CaoNiMaDeUc(){
	//清除UC手机浏览器强制链接
	$("a").each(function(index, element){
		try{
			var thishref=$(this).attr("href");
			var thisText=$(this).html();
			if(thishref.indexOf("uc.cn")>=0){$(this).replaceWith(thisText);};
		}catch(e){};
	});
	//清除UC手机浏览器强制控制
	$("script").each(function(index, element){
		try{
			var thissrc=$(this).attr("src");
			if(thissrc.indexOf("ucbrowser")>=0){$(this).remove();};
		}catch(e){};
	});
	//清除UC手机浏览器强制广告
	var ucad=document.getElementById('uc_recommend_ad');
    if(ucad){
        ucad.parentNode.removeChild(ucad);
    };
};
//处理UC浏览器
setTimeout(function (){CaoNiMaDeUc();},2000);
	
3. 屏蔽原理
a) 我们可以通过JS延迟输出页面,就可以看到劫持后添加的代码。
b) 然后通过分析代码,对代码进行相应的禁止。
c) 我们目前使用的是禁止加载相关控件的方法,进入拦截,也可以使用其它方法拦截,下面是一些其它方法的简单介绍,方法未经测试。
4. 通过CSS样式的优先级屏蔽。
div[id^="_"] { display: none !important; }
5. 隐藏iframe引入方法。
	
iframe[id^="head__"]{display: none !important;}
	
6. 代码图片
	
 
            辽公网安备21010402000436号 
            
            辽ICP备14018187号-7 
            
            网上亮照 电子执照 
            
            安全有保障更放心 
            
            