2012-01-30 117 views
-1

我有一個頁面,每頁有大約50篇博客文章。每篇博客文章的內容都隱藏着CSS,並在用戶點擊博客文章標題時顯示。當用戶點擊標題時,是否有辦法將AdSense內容動態添加到每篇博文中? Google允許嗎?使用Adsense添加動態廣告

我知道我可以在頁面上添加50個廣告,並用css隱藏它們,直到用戶點擊博客標題,但效率非常低。

這是林試圖做:

例子:

http://jsfiddle.net/WZG2U/

HTML:

<div id="post1"> 
<h1>Blog Post 1</h1> 
<p class="hidden">This is the content for blog post.</p> 
</div> 

CSS:

body { 
    padding:30px; 
} 

* { 
    font-family:arial; 
} 

h1 { 
    font-weight:bold; 
    cursor:pointer; 
    font-size:20px; 
} 

p.hidden { 
    display:none; 
} 

div.ad { 
    float:right; 
    background-color:red; 
    height:100px; 
    width:100px; 
    color:#ffffff; 
    font-weight:bold; 
    font-size:11px; 
    text-align:center; 
} 

腳本:

$("h1").click(function() { 

    var thisid = $(this).parent().attr("id"); 

    if ($("div#"+thisid+ " p").hasClass("hidden")) { 
     $("div#"+thisid+ " p.hidden").removeClass("hidden"); 

     // insert dymanic adsense ad 
     $("div#"+thisid+ " p").before('<div class="ad">insert dynamic adsense ad here!</div>'); 
    } else { 
     $("div#"+thisid+" p").addClass("hidden"); 
     $("div#"+thisid+" div.ad").remove(); 
    } 

}); 
+0

所以,你有什麼似乎正在工作的代碼...你遇到問題?你在問什麼? – cdeszaq 2012-01-30 18:28:02

+0

我的問題是有沒有辦法動態地添加AdSense內容到每個博客文章? Google允許嗎? – supercoolville 2012-01-30 18:30:20

回答

0

這是給博客模板,如果它可以廣告代碼中動態添加到內容到頁面或沒有。 Blogger擁有使用AdSense廣告的獲利標籤,並在創建頁面時動態地將代碼展示給網頁。該頁面必須使用純HTML格式,這意味着您必須使用純文本而不是腳本文本,否則AdSense機器人將無法行走以確定與頁面的廣告相關性,因此可能會被禁止。我的意思是說你並不是想在ajax中完全寫一個頁面,或者你是這樣的?