This article mainly introduces how to use arrays in js to search by using strings (shielding advertisements to determine URLs, etc.). For more information, see
1. Ad shielding
Sometimes our ad pages are controlled by js in a unified manner, and some pages do not want to display part of the ads, so we only need the id of the Article. Pure string search is simple and effective, and the script house is also in use.
Var ad_softlist = ', 133015,155868, 146429,'; if ("undefined "! = Typeof softid) {// judge whether the article id exists. if it does not exist, it is not executed. Generally, var softid = 45465 is defined on the page. if (softid! = Null & ad_softlist.indexOf (',' + softid + ',') =-1) {// display advertisement, softid is the article id}
2. Determine whether the url complies with simple rules.
The combination of arrays and strings makes the structure simple by using arrays because the judgment requires two parts.
It turns out that there will always be web site errors during the update process:
Example: http: // http://www.jb51.net
Htp. Therefore, we have written down several commonly used URLs. For more information, see the code.
Function checkurl (urls) {if (urls! = "") {If (urls. indexOf ('HTTP: // http ')! =-1) | urlcheck (urls )! = True) {alert ("there is a problem with the URL. You can check the newly added URL") ;}} function urlcheck (str) {var urlall = "http: //, https: //, ed2k: //, thunder: //, flashget: //, ftp: // "; var urlarr = urlall. split (","); for (var I = 0; I
-1) {return true;} return false ;}
Usage:
I am afraid that the data cannot be submitted due to mistaken kill. It serves only as a friendly reminder and is not returned by the form check.
The original Article of the script house. For details, sign it.