先加載完頁面再加載廣告的原理:
網頁打開的順序都是按頁面從上到下的順序加載完成的,所以要想使廣告不影響頁面打開速度,就要等頁面全部打開完成后,再加載JS代碼。等頁面加載完再加載廣告其實就是將廣告的 JS 代碼放在頁面的底部,等頁面內容打開完成后再加載到廣告代碼,再用頁面上預留好的的 DIV 輸出廣告。
使用方法:
1、將以下代碼放置頁面中想要放廣告的地方
上面的方法可以加載任何方式的廣告,但現在百度與google的都不讓使用了,容易造成廣告的二次加載,點擊率也會降低。下面武林網小編為大家分享下,比較新的加載廣告的方式:
1、可以加載字符串類型與google類型的
<div id="logo_m"></div><script>function doad(datastr,id){ //getid(id).innerHTML = datastr; 這個是原生js的寫法$("#"+id).html(datastr); //這個是jquery寫法}/*上面的都是直接的字符串寫入,不能是js代碼下面的代碼利用的是jquery的append加載google廣告不錯,百度的好像不能用。后加載百度的可以是用百度管家自帶的函數。*/function doad2(datastr,id){ $("#"+id).append(datastr);}var logo_m='<a target="_blank"><img src="http://files.VeVB.COm/image/kongbao_370.gif" width=370 height=60 /></a>';doad(logo_m,'logo_m');</script>2、可以加載google廣告的代碼
$(document).ready(function(){ $('#google_ads_1').append("" + "<script src=/"http:////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>");});一般都是頁面完全加載完,再加的廣告,當然現在google現在新出的異步加載廣告的代碼也是挺快的,不會卡網頁了。
上面的都是后加載google的異步廣告代碼。
對于這樣的字符加載方法,個人不太喜歡,我還是比較喜歡這樣的,代碼如下
var botad='<script async src="http://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、可以加載百度廣告聯盟的代碼
百度管家自帶的后加載廣告的代碼,基于jquery
<div id="tonglanbd"></div><script type="text/javascript">$.getScript("http://cbjs.baidu.com/js/m.js", function() {BAIDU_CLB_fillSlotAsync("廣告id,不能帶u","tonglanbd");});</script>新聞熱點
疑難解答