CSS removes free VM ads

Source: Internet
Author: User

I believe most web developers have experience using free virtual hosts? Haha, whether it's for experimentation, novice hands-on training, or some inexplicable use, you are reluctant to spend money to buy paid virtual hosts. Free space is very useful. However, we have noticed that the better the free virtual host, the more annoying the forced advertisement will be placed.

I learned that the quality of many free virtual hosts in foreign countries is far better than that of paid virtual hosts in China. For example, the Japanese virtual host I applied for at sitemix.jp has a capacity of 1.5 GB, supports PhP5, Unlimited Traffic, unlimited CPU, unlimited MySQL database space, and comes with the latest version of WordPress, which is fast and stable; if it is a domestic paid virtual host, it will be at least RMB/year. Believe it? Well, in order to test its performance to the maximum extent, I applied for an automatic acquisition station that would consume a lot of resources, which is simply a general feeling (onlookers address http://degreeus.co.cc /). This is not a case, like I applied for a free virtual host on a Russian website, and even can put more resource-consuming Text Database Web games (onlookers: http://www.sixsix.tu2.ru /). Note: More than half of the charged virtual hosts in China are not allowed to be stored on the Collection site and web game site, because it will occupy too much resources.

Okay, so much. Return to the question.

As I said just now, experience tells us that the better the free virtual host, the more advertisement will be placed. Because the pop-up window advertisement method has become dedicated to Rogue, the free virtual hosting machine inserts the advertisement method almost to the HTML Tag. The specific operations are basically the same as those of "hackers" who drive trojans on their websites. The two methods are nothing more than the following.

    1. Write ads through JavaScript (red box section, demo address http://degreeUs.co.cc/ad.htm)
    2. Insert ad by force insert IFRAME (red box section; demo address http://sango.toypark.in/ad.htm)

First, let's look at the IFRAME method.

ViewSource code, Found such a line

Oh, I see, when the Space Provider outputs HTML on the Web server, force Replace the "<body>" of all webpages with the form of "<body> <div> <IFRAME/> </div>". IFRAME contains advertisement pages, in this way, a forced advertisement similar to a website Trojan is formed.

There are many ways to get rid of IFRAME ads. This article only discusses how to use CSS to process them.

As we all know, CSS can directly describe the appearance of a visual tag. For example, P {color: Red} indicates that the text color in all P marks on the webpage will change to Red. Isn't IFRAME a mark? Come:

IFRAME {... the CSS that describes the appearance is written here.Code;};

SpecificallyIFRAME {ad: expression (this. src = 'about: blank ', this. outerhtml = '');}

First, select all IFRAME and define a CSS attribute, such as Ad. Set the IFRAME embedded URL to null through expression. Finally, remove the IFRAME tag by setting the outerhtml attribute. This will solve the problem ~

Demo with advertisement: http://sango.toypark.in/ad.htm

Demo of removing ad: http://sango.toypark.in/noad.htm

 

Next we will discuss how to use JavaScript-based advertisements.

First, let's first think about two questions: 1. Where can I insert Javascript into a space chamber to ensure that the Javascript inserted by the Space chamber can run normally without damaging the original webpage? A general method is required for every website. 2. What is the content in JavaScript?

All the friends who have done the website know that they are similar to inserting iframe. Since each webpage has two tags: <body> and </body>, the Space Provider generally chooses to replace one of them, for example, replace </body> with <SCRIPT src = '... '/> </Body>. In order not to affect the original appearance of the web page, the Space Provider generally replaces the </body> instead of the <body>. This is more user-friendly and the advertisement is placed at the end, that is, the advertisement is loaded only after all content is loaded.

The principle is so simple that it is easy to remove the advertisement. The most common is to use the <NoScript> tag and write targeted JavaScript to remove the advertisement. Of course, what I like most is also the most operational, that is, the use of CSS, is also the smallest way to modify the website.

What should we do? This requires the second question just raised. What is in JavaScript? Generally, space vendors like links and advertisements with styles. Therefore, JavaScript is often written into a div (or IFRAME, you can use the above method ). For the most common Div writing, we only need to get this Div through the DOM operation and set its style to 'display: none. How to get this div? In either case, the DIV has an ID. You can write a style definition similar to "# ID {}" In css. If this Div does not have an ID, we know that it must be the last DIV in the DOM structure (because it is close to </body>). Use the getelementsbytagname () method of Dom to combine with the lastchild attribute.

The DIV of the demo address has an ID, which is very lucky. After finding its ID, we only need to write it like this in the globally referenced CSS file:

# Sitemix_pr_footer {display: none ;}

Demo with advertisement: http://degreeUs.co.cc/ad.htm

Demo of removing ad: http://degreeus.co.cc/whole site.

There are various ways to AD, because the ways in which space providers insert advertisements are different, but they share the same principle, whether advertising or ad. Some spatial commerce advertisements are a little more complicated (such as websamba in the past), but they can also be solved through CSS, JavaScript (CSS expression) and Dom, which are usually a one or two sentences of code. I'm not very familiar with it. I can't say what technical skills I have. It's just my experience! Well, everyone is enthusiastic about the discussion.

I hope that you will never give up on the virtual host with strong advertisement insertion in the future. If you have a little bit of brains, you will be able to get rid of the advertisement! This is very important because advertisements are usually inserted in a space that is easy to use.

O (worker _ worker) O.

Thank you!

Related Article

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.