昨天,在處理動態新增Google Adsense廣告字串的時候,遇到了一些問題,就是Google Adsense的程式碼字串,
不能單純的只用Response.Write輸出,這樣會把所有的程式碼都連在一起...
昨天,在處理動態新增Google Adsense廣告字串的時候,遇到了一些問題,就是Google Adsense的程式碼字串,
不能單純的只用Response.Write輸出,這樣會把所有的程式碼都連在一起,變成下面的樣子輸出:
1 <script type="text/javascript"><!-- google_ad_client = "pub-xxxxxxxx";
2 google_ad_slot = "xxxxxxxx"; google_ad_width = 600; google_ad_height = 100;
3 //--></script><script type="text/javascript"
4 src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2 google_ad_slot = "xxxxxxxx"; google_ad_width = 600; google_ad_height = 100;
3 //--></script><script type="text/javascript"
4 src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
可是這樣輸出並不會正常的讓Google Adsense正常顯示,但一直百思不得其解如何要讓輸出的字串斷行,
經過同事提點之後,原來加上VbCrlf可以有斷行的效果,所以加上VbCrlf試試,果然廣告正常出現了,程式碼如下:
01
Dim strGoogleAD As String = String.Empty
02
03
strGoogleAD = "<div class=""spacer""></div> " _
04
& vbCrLf & "<script type=""text/javascript""> " _
05
& vbCrLf & "<!-- " _
06
& vbCrLf & "google_ad_client = ""pub-xxxxxxxxxxxxx""; " _
07
& vbCrLf & "google_ad_slot = ""xxxxxxxxxx""; " _
08
& vbCrLf & "google_ad_width = 600; " _
09
& vbCrLf & "google_ad_height = 100; " _
10
& vbCrLf & "//--> " _
11
& vbCrLf & "</script> " _
12
& vbCrLf & "<script type=""text/javascript""" _
13
& vbCrLf & "src=""http://pagead2.googlesyndication.com/pagead/show_ads.js""> " _
14
& vbCrLf & "</script> " _
15
& vbCrLf & "<div class=""spacer""></div> "
16
17
Response.Write(strGoogleAD)

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17
