ASP AdRotator 組件
每當使用者進入網站或重新整理頁面時,ASP AdRotator組件就會建立一個AdRotator對象來顯示一幅不同的圖片。
文法:
以下為引用的內容: <% set adrotator=server.createobject("MSWC.AdRotator") adrotator.GetAdvertisement("textfile.txt") %> |
執行個體
假設我們有一個檔案名稱為"banners.asp"。它類似於這樣:
以下為引用的內容: <html%> <body%> <% set adrotator=Server.CreateObject("MSWC.AdRotator") response.write(adrotator.GetAdvertisement("ads.txt")) %> </body%> </html%> |
檔案"ads.txt"類似這樣:
以下為引用的內容: * webjxcom.gif http://www.webjx.com/ Visit Webjx.Com 80 microsoft.gif http://www.microsoft.com/ Visit Microsoft 20 |
"ads.txt"檔案中星號下面的代碼定義了如何顯示這些映像,連結地址,映像的替換文本,在每百次點擊中的現實幾率。我們可以看到,W3School圖片的顯示幾率是80%,而Microsoft圖片的顯示幾率是20%。
注釋:為了使這些連結在使用者點擊時可以正常工作,我們需要對檔案"ads.txt"進行一點點小小的修改:
以下為引用的內容: REDIRECT banners.asp * webjxcom.gif http://www.webjx.com/ Visit Webjx.Com 80 microsoft.gif http://www.microsoft.com/ Visit Microsoft 20 |
轉向頁面會接收到名為url的變數的查詢字串,其中含有供轉向的URL。
注釋:如需規定映像的高度、寬度和邊框,我們可以在REDIRECT下面插入這些代碼:
以下為引用的內容: REDIRECT banners.asp WIDTH 468 HEIGHT 60 BORDER 0 * webjxcom.gif ... ... |
最後要做的是把這些代碼加入檔案"banners.asp"中:
以下為引用的內容:
<% url=Request.QueryString("url") If url<>"" then Response.Redirect(url) %> <html> <body> <% set adrotator=Server.CreateObject("MSWC.AdRotator") response.write(adrotator.GetAdvertisement("textfile.txt")) %> </body> </html> |