1. Ad blocking
Sometimes our advertising pages are uniformly controlled with js. Some pages do not want to display some ads, so we only need the id of the article. Pure string search is simple and effective. Script Home also uses it
var ad_softlist = ',,133015,155868,146429,'; if("undefined" != typeof softid){ //判断文章id是否存在,不存在就不执行,一般页面中会定义好var softid=45465; if(softid!=null && ad_softlist.indexOf(','+softid+',')==-1){ //显示广告,softid就是文章id }
2. Determine whether the URL conforms to simple rules
Combine arrays and strings, because judgment requires two parts, using arrays makes the structure simple
It turns out that we always have URL errors during the update process:
For example: http://http://www.jb51.net
htp:// and other error conditions. So we have written down all the commonly used URLs. See the code for details.
function checkurl(urls){ if(urls!=""){ if((urls.indexOf('http://http')!=-1) || urlcheck(urls)!=true ){ alert("网址有问题吧,可以再检查一下刚加的网址"); } } } function urlcheck(str){ var urlall="http://,https://,ed2k://,thunder://,flashget://,ftp://"; var urlarr=urlall.split(","); for(var i=0;i<urlarr.length;i++){ if(str.indexOf(urlarr[i])>-1){ return true; } } return false; }
How to use:
I am afraid that the data cannot be submitted due to accidental killing. It is just a friendly reminder and I did not write the form to check the return.
Original article by Script House, please sign
for reprinting