實施Google Ads但嘗試根據$(document).width()嘗試投放兩個廣告腳本中的一個。
閱讀並儘可能以最佳方式進行搜索,並且迄今爲止我所得到的內容不會顯示爲中斷(沒有可見錯誤),除非它實際上並未插入Google廣告。 (燁,錯過整點有!)
首先,我設置的區域來保存廣告:
<div id="google-ad"></div>
其次是邏輯,以確定該文件的寬度,並插入必要的谷歌廣告腳本:
if ($(document).width() < 728) {
$("#google-ad").html('<script type="text/javascript"><!--google_ad_client = "ca-pub-GOOGLE-ID";/* AD NAME HERE */google_ad_slot = "GOOGLE-NUMBER"; google_ad_width = 320; google_ad_height = 50;//--><\/script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><\/script>');
} else {
$("#google-ad").html('<script type="text/javascript"><!--google_ad_client = "ca-pub-GOOGLE-ID";/* AD NAME HERE */google_ad_slot = "GOOGLE-NUMBER"; google_ad_width = 728; google_ad_height = 90;//--><\/script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><\/script>');
});
從理論上講,我認爲這有效,但實際上並不奏效。所以,我當然做錯了一些事情。歡迎任何幫助或指導。
謝謝。
你結束腳本標籤應該是 – VIDesignz
不如果你自己包含'$(「#google-ad」)。html('...')這兩行,那麼任何一行都可以工作? @VIDesignz - 我認爲'<\/script>'在字符串文字中是爲了阻止瀏覽器看到''並結束腳本塊。 – nnnnnn
最後);不應該在那 – VIDesignz