ASP Content Rotator

用 ContentRotator 轮播任意 HTML 片段、内容文件格式。

Intermediate
Key PointsContentRotator 与 AdRotator 类似,但轮播的是任意 HTML 片段,不限于图片链接。

内容文件

Text
%% 2
<h3>春季促销</h3>
<p>全场八折,仅限本周。</p>

%% 1
<h3>新品上市</h3>
<p><a href="/new">看看有什么新的</a></p>

%% 1
<div class="tip">提示:按 Ctrl+S 可以保存草稿。</div>

%% is followed by a weight controlling selection probability; equal numbers mean an even rotation. Entries are separated by blank lines.

页面里用

ASP
<%
    Dim cr
    Set cr = Server.CreateObject("MSWC.ContentRotator")

    Response.Write cr.ChooseContent("/content/tips.txt")

    Set cr = Nothing
%>
Output
<h3>春季促销</h3>
<p>全场八折,仅限本周。</p>

全部内容

ASP
<%
    Response.Write cr.GetAllContent("/content/tips.txt")
%>

GetAllContent prints every entry in order, useful for an announcement list. Weights are ignored.

与 AdRotator 的差别

ContentRotator
Content图片 + 链接任意 HTML
Click tracking自带重定向脚本没有
Size controlWIDTH / HEIGHT自己写 CSS
Use横幅广告提示、公告、推荐位
ContentRotator emits raw HTML without escaping. The content file must be trusted, admin-maintained content; allowing user submissions would let them inject arbitrary scripts.

自己实现更可控

ASP
<%
    ' 从数组里随机挑一条,逻辑透明、易调试
    Dim tips, i
    tips = Array( _
        "<h3>春季促销</h3><p>全场八折。</p>", _
        "<h3>新品上市</h3><p><a href=""/new"">看看新的</a></p>", _
        "<div class=""tip"">按 Ctrl+S 保存草稿。</div>")

    Randomize
    i = Int(Rnd() * (UBound(tips) + 1))
    Response.Write tips(i)
%>

Rnd() needs Randomize, or every request gets the first value of the same sequence — the symptom being "the rotator always shows the same item". The most common VBScript randomness bug.

Friends & Partners