2012-08-13 59 views
1

我想在Chrome擴展中添加adsense代碼(manifest_version:2)。如何在Chrome擴展中添加AdSense代碼?

我有,我有一個專門的塊是廣告popup.html頁:

<div id="adblock"> 
      <script type="text/javascript"><!--google_ad_client = "ca-pub-xxxxxx";/* Getfiles Chrome Extn Banner 468x60 */google_ad_slot = "xxxxxx"; google_ad_width = 468;google_ad_height = 60;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 
     </div> 

但在執行時會生成以下錯誤:

Refused to load the script 'http://pagead2.googlesyndication.com/pagead/show_ads.js' because it violates the following Content Security Policy directive: "script-src 'self' https://pagead2.googlesyndication.com/pagead/show_ads.js". 

這是由於禁止內聯javascript的新內容安全策略。

爲了克服這個問題我試圖創建代碼popup.js文件

document.addEventListener('DOMSubtreeModified', function() { 

       var x = chrome.extension.getViews({type:"popup"}); 
       rowOutput='<script type="text/javascript"><!--google_ad_client = "ca-pub-xxxx";/* Getfiles Chrome Extn Banner 468x60 */google_ad_slot = "xxxx"; google_ad_width = 468;google_ad_height = 60;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>'; 
       if (x.length>0){ 

        x[0].document.getElementById('adblock').innerHTML=rowOutput; 
       } 
}, true);   

當我重新加載擴展,然後點擊擴展圖標,瀏覽器掛起並彈出不列入開放。

回答

相關問題