Commonly used Baidu Alliance advertising method of asynchronous loading

Source: Internet
Author: User

Asynchronous advantages: The implementation of the ad asynchronous loading, does not affect the loading speed of the page itself!

Scope of application: text, pictures and flash type advertising material on fixed advertising position


The Federation code does not currently have asynchronous loading, but the ad bit created by Baidu's ad Butler can also build federated materials and provide a variety of loading methods that can be used with the following code if the page has been loaded with jquery

The code is as follows Copy Code
$.getscript ("Http://cbjs.baidu.com/js/m.js", function () {
Baidu_clb_fillslotasync ("12345", "your_id");
Baidu_clb_fillslotasync ("23456", "Your_id2");
});

If nested into JQuery's ready function, this kind of load advertisement will not affect the page speed, of course, the display of ads according to the page is different, there will be a certain delay. If you're looking for a website speed and don't care about how fast the ad is loading, we can even put it in a settimeout, The countdown is 1-2 seconds before the ad is triggered.

-
If you do not load jquery, you can use the native asynchronous Load method

The code is as follows Copy Code

<div id= "Loadad" ></div>
<div id= "Loadad1" ></div>
<div id= "Loadad2" ></div>
<div id= "Loadad3" ></div>

<script type= "Text/javascript" src= "Http://cbjs.baidu.com/js/m.js" ></script>
<script type= "Text/javascript" >
Baidu_clb_fillslotasync ("u1268881", "Loadad");
Baidu_clb_fillslotasync ("u1268881", "loadad1");
Baidu_clb_fillslotasync ("u188581", "loadad2");
Baidu_clb_fillslotasync ("u126781", "loadad3");
</script>

Effect

Of course, there is a situation, do not want to load jquery to use settimeout to do the countdown, you can refer to the Google Statistics code to write

The code is as follows Copy Code

var cpro_id = "u123456";
settimeout (function () {
(function () {var du = document.createelement (' script '); du.type = ' text/javascript '; du.src = ' http:// Cpro.baidustatic.com/cpro/ui/c.js '; var s = document.getelementsbytagname (' script ') [0]; S.parentnode.insertbefore (Du, s);}) ();
},1000);


JS or picture ads are loaded asynchronously

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

The code is as follows Copy Code

<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.

The code is as follows Copy Code

<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 implementation of the first load page before loading ads, how do not affect you read 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.