2011-03-12 61 views
0

我在我的asp.net網頁中嵌入了一個google AD代碼,這會導致我的網頁加載速度變慢。如何在asp.net網頁的後臺加載Google AD代碼?

有沒有辦法在後臺加載Google AD代碼?我希望先顯示其他網頁內容並最後顯示Google AD。

<script type="text/javascript"><!-- 
    google_ad_client = "pub-5823168326939016"; 
    /* HiCalc 234x60 On 10-10-22 */ 
    google_ad_slot = "1050696847"; 
    google_ad_width = 234; 
    google_ad_height = 60; 
//--> 
</script> 
<script type="text/javascript" 
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 
+0

如何廣告的許多人已在您的網頁,並在女巫的地方? (在頂部/底部/中間等)? – Aristos 2011-03-12 10:22:51

回答

0

理論上,你可以。解決方法1:不要直接將AD代碼包含到頁面中,而是在使用javascript/AJAX加載頁面時獲取它(jQuery.get()將正常工作)並將其插入頁面中。我已經測試過,並且在添加到頁面DOM(文檔對象模型 - 頁面內容)時,通過ajax技術加載的代碼得到執行。解決方法2:更改AD代碼,只是用一些內容元素包圍它,如<textarea>(AD代碼在此處)</textarea >。然後,當頁面加載時,運行一個JavaScript代碼,它獲取TextArea內容並將其添加到頁面DOM。

注意:我不是100%確定這將在所有瀏覽器上按預期工作,但它應該。

注2:我不是100%確定哪些規則是由谷歌的AdSense所迫,也許這個解決辦法違反了其中的一些......但我認爲這是確定:-)

編輯

下面是頁面代碼:

<script language="javascript" type="text/javascript"> 
    jQuery(document).ready(function() { 
     jQuery.get('/AdCode.aspx', null, function (data) { 
      jQuery('.ad-code-container').html(data); 
     }); 
    }); 
</script> 

<div id="d1" class="ad-code-container"> 
</div> 

這裏是AdCode.aspx文件代碼:

<@ Page Language="C#" Leave here whatever your app has %> 

<script type="text/javascript"> 
    google_ad_client = "pub-5823168326939016"; 
    google_ad_slot = "1050696847"; 
    google_ad_width = 234; 
    google_ad_height = 60; 
</script> 
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 

我希望這可以幫助。

+0

謝謝!你能寫一個解決方案1的代碼嗎? – Paul 2011-03-12 07:53:29

+0

非常感謝! 1.爲什麼要將「<@ Page Language =」C#「Leave your here what app has%>」添加到AdCode.aspx? 2.您確定您的代碼不會違反Google政策100%嗎? – Paul 2011-03-16 13:31:19

+0

請參閱注2.使用這完全是你的責任。我個人以Google提供的方式使用廣告代碼。 – Tengiz 2011-03-16 13:35:45

0
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" type="text/javascript"></script 

你需要在腳本代碼使用異步字加載廣告異步

相關問題