JavaScript ads after loading, loading the page reload ads _javascript Tips

Source: Internet
Author: User

Load the page before loading the principle of advertising:

The order of the page is in order to load the page from top to bottom to complete, so want to make the advertisement does not affect the page to open the speed, must wait for the page all open completes, then loads the JS code. After the loading of the page loaded ads is actually the ads will be the JS code at the bottom of the page, and so on after the completion of the page content and then loaded into the advertising code, and then use the page to set aside a good DIV output ads.

How to use:
1, place the following code in the page where you want to put the ads

Copy Code code as follows:

<div id= "MyAds" > Loading ...</div>

2, the code will be placed at the bottom of the page, that is, the bottom of the footer,php file.
Copy Code code as follows:

<div id= "Span_myads" > Place Advertising Code </div>
<script type= "Text/javascript" >
document.getElementById ("MyAds"). InnerHTML = document.getElementById ("Span_myads"). InnerHTML;
document.getElementById ("Span_myads"). InnerHTML = "";
</script>


OK, so that the completion of the first load of the page and then load the advertisement, how does not affect everyone to read it.

The above method can load any way of advertising, but now Baidu and Google are not allowed to use, easy to cause ads two load, click rate will also be reduced. Under the cloud Habitat Community Small series for everyone to share, compare the new load advertising way:

1, can load string type and Google type of

<div id= "Logo_m" ></div>
<script>
function Doad (datastr,id) { 
//getid (id). InnerHTML = DATASTR; This is the original JS writing
$ ("#" +id). HTML (DATASTR);//This is jquery
writing}/
* above are
direct string writes, cannot be JS code
The following code uses the jquery append to load Google ads well, Baidu seems to be useless. After loading Baidu can be used with the function of the butler with Baidu.
*/
function doad2 (datastr,id) { 
$ ("#" +id). Append (Datastr)
;

var logo_m= ' <a href= "http://www.danhw.com/" target= "_blank" ></a> ';
Doad (logo_m, ' logo_m ');
</script>

2, can load the code of Google ads

$ (document). Ready (function () {
	$ (' #google_ads_1 '). Append ("" +
	"<script src=\" \/\/ Pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\ "><\/script>" +
	"<!--question-side--> "+
	" <ins class=\ "adsbygoogle\" "+
	"   style=\ "display:inline-block;width:728px;height:90px\" "+
	"   data-ad-client=\" ca-pub-345345345345\ "" +
	"   data-ad-slot=\" 345345345\ "></ins>" +
	" <script> "+
	"  (adsbygoogle = Window.adsbygoogle | | []). push ({}); +
	"<\/script>");

Generally is the page completely loaded, and then add the ads, of course, now Google's new asynchronous load of the code is also very fast, will not card page.
The above are all the asynchronous ad code that loads Google.

For such a word alphanumeric load method, the individual does not like, I still prefer this, the code is as follows

var botad= ' <script async src= '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js ' ></script> ';
botad+= ' <ins class= ' adsbygoogle ' style= ' display:inline-block;width:336px;height:280px ' data-ad-client= ' ca-pub-343534534 "data-ad-slot=" 6343459 "></ins><script> (adsbygoogle = Window.adsbygoogle | | []). push ({});</script> ';

$ (document). Ready (function () {
	$ (' #google_ads_1 '). append ();

3, can load Baidu Advertising alliance code
Baidu Butler brought the code after the load ad, based on jquery

<div id= "TONGLANBD" ></div>
<script type= "Text/javascript" >
$.getscript ("http:// Cbjs.baidu.com/js/m.js ", function () {
Baidu_clb_fillslotasync (" Ad ID, cannot take U "," TONGLANBD ");
});
</script>

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.