ASP Content Rotator
用 ContentRotator 轮播任意 HTML 片段、内容文件格式。
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 control | WIDTH / 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.
内容文件
Text
%% 2
<h3>春季促销</h3>
<p>全场八折,仅限本周。</p>
%% 1
<h3>新品上市</h3>
<p><a href="/new">看看有什么新的</a></p>
%% 1
<div class="tip">提示:按 Ctrl+S 可以保存草稿。</div>%% 后面跟权重。权重决定被选中的概率,写成相同数字就是均匀轮播。每条之间用空行分隔。
页面里用
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 把所有片段按顺序全输出,适合做「公告列表」这类不需要轮播的场景。它忽略权重。
与 AdRotator 的差别
| AdRotator | ContentRotator | |
|---|---|---|
| 内容 | 图片 + 链接 | 任意 HTML |
| 点击统计 | 自带重定向脚本 | 没有 |
| 尺寸 | WIDTH / HEIGHT | 自己写 CSS |
| 适用 | 横幅广告 | 提示、公告、推荐位 |
ContentRotator 输出的是原样 HTML,不转义。内容文件必须是管理员维护的可信内容——如果允许用户投稿,就等于允许他们往页面里注入任意脚本。自己实现更可控
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() 必须配 Randomize,否则每次请求拿到同一序列的第一个值——表现是「轮播永远显示同一条」。这是 VBScript 里最常见的随机数错误。