Js array combined with strings for search (blocking advertisement judgment url, etc.) _ javascript skills

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.