(Original) How can I trigger a Google Adsense advertisement in a blog? (Web) (CSS) (JavaScript)

Source: Internet
Author: User

Abstract
Generally, a blog will provide a free token in the two regions, so that you can easily put Google Adsense's Javascript. if you wantArticleGoogle Adsense is also included in this article. Do you have a copy & Paste article?

Introduction
If the author says that he has made great achievements in the article, the author should pay attention to the content of the article, when the website is closed, the website will surely see an announcement, but you may not be able to pay attention to the two messages on the Internet. If you need to copy & Paste the Google Adsense JavaScript For every article, it's too troublesome !!

This article uses JavaScript to generate the following Google Adsense warning. After the warning, it is normal in IE6, IE7, and Firefox 2.

The javascript of Google Adsense is as follows:

1 < Script Type = "Text/JavaScript" > <! --
2 Google_ad_client =   " Pub-1, 8345123166060053 " ;
3 /* 728x90, 2008/5/15 */
4 Google_ad_slot =   " 3609602782 " ;
5 Google_ad_width =   715 ;
6 Google_ad_height =   90 ;
7 // -->
8 </ Script >
9 < Script Type = "Text/JavaScript"
10 SRC = "Http://pagead2.googlesyndication.com/pagead/show_ads.js" >
11 </ Script >


However, because we do not have the source code of the blog, and the free memory of many blogs is only in the left and right sides, google Adsense reports can be placed anywhere on the blog unless we have moved the above JavaScript scripts to every article.

We will make some changes to the above Javascript

1 < Script Type = "Text/JavaScript" > <! --
2 Google_ad_client =   " Pub-1, 8345123166060053 " ;
3 /* 728x90, 2008/5/15 */
4 Google_ad_slot =   " 3609602782 " ;
5 Google_ad_width =   715 ;
6 Google_ad_height =   90 ;
7 // -->
8 </ Script >
9 < Div ID = "None_ads" Style = "Display: none" >
10 < Script Type = "Text/JavaScript"
11 SRC = "Http://pagead2.googlesyndication.com/pagead/show_ads.js" >
12 </ Script >
13 </ Div >
14
15 < Script Type = "Text/JavaScript" >
16 C = Document. getelementbyid ( " Ajaxholder_updatepanel1 " );
17 If (C ! =   Null ){
18 Div = Document. getelementbyid ( " None_ads " );
19 C. innerhtml = Div. innerhtml + C. innerhtml;
20 }
21 </ Script >


The above Javascript is based on two concepts. Using this method, you can place Google Adsense anywhere in the blog:
1. hid the generated JavaScript code in an invisible <div>.
2. Locate the html id you want to insert and insert the advertisement.

1 ~ 8 rows

< Script Type = "Text/JavaScript" > <! --
Google_ad_client =   " Pub-1, 8345123166060053 " ;
/* 728x90, 2008/5/15 */
Google_ad_slot =   " 3609602782 " ;
Google_ad_width =   715 ;
Google_ad_height =   90 ;
// -->
</ Script >

Set the billing result. The changes between google_ad_client and google_ad_slot cannot be changed. If you change the value, you will not receive the money. However, google_ad_width and google_ad_height are set to the warning degree and height. If the warning degree and height are not in line with your website configuration, you can modify the degree of parallelism.

9 ~ 13 rows

< Div ID = "None_ads" Style = "Display: none" >
< Script Type = "Text/JavaScript"
SRC = "Http://pagead2.googlesyndication.com/pagead/show_ads.js" >
</ Script >
</ Div >

Hiding the JavaScript code of Google Adsense in a <div> is invisible to <div> by the CSS "display: none, at this time, JavaScript will be converted into <IFRAME> content.

15 ~ 21 rows

< Script Type = "Text/JavaScript" >
C = Document. getelementbyid ( " Ajaxholder_updatepanel1 " );
If (C ! =   Null ){
Div = Document. getelementbyid ( " None_ads " );
C. innerhtml = Div. innerhtml + C. innerhtml;
}
</ Script >

Therefore, if I want to place an alert message before ajaxholder_updatepanel1 <div>, use getelementbyid () to locate this <div>, you can use Internet Explorer developer toolbar to view the ID of the HTML to be added.

Then find the hidden none_ads <div>, so I want to put it before ajaxholder_updatepanel1, so I will add the innerhtml of the hidden <div> to the original innerhtml, innerhtml is the W3C standard, so it can be used with peace of mind and supported by each JavaServer.

How did I add traditional Chinese (Traditional Chinese) to my blog? Why does the W3C Dom not provide insertafter? (Web) (JavaScript): the method used to insert HTML into a tag. However, this method adds innerhtml, this requirement can also be customized.

Remark
When I tried it, I found that if you put three Google Adsense advertisements at the same time on your website, there is no problem with using dynamic Copy & Paste JavaScript, if you use dynamic JavaScript, the last warning may not be displayed, but the cause is unknown.

Conclusion
Through the above methods, you can also trigger a Google Adsense advertisement for any part of your blog, not just for the two sides of the blog.

See also
(Original) how to add traditional Chinese (Traditional Chinese) to a blog? (Web) (CSS) (JavaScript)
Why does W3C Dom not provide insertafter? (Web) (JavaScript)

reference
you do not need to cut down the following article: in this article, Google Adsense announcement was generated.
the ultra-bitter Ga [JavaScript] Put Google Adsense in Header banner
Internet Explorer developer toolbar

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.