0

我继承了一个主要是 vbscript/asp 的网站。一页在 DOCTYPE HTML PUBLIC... 行之前有 <% vbscript %> 并在页面打开之前运行。即使用户按下另一个页面上的后退按钮到达那里,我也需要让它运行。大概是通过将其放置在一个 onload 函数中-正确吗?

这是 <% %> 代码的一小段:

<%
if not (IsEmpty(Session("MM_Username"))) then
    Set checkSet = Server.CreateObject("ADODB.Recordset")
        checkSet.ActiveConnection = MM_CA_STRING
        checkSet.Source = "SELECT * FROM cpgdb.dbo_tbl_printing_tempstore WHERE username = '" & Session("MM_username") & "' AND addedtocart = 'NO'"
        checkSet.Open()

end if
%>
<!DOCTYPE HTML PUBLIC...
...
<body>

我想我需要让它像这样运行:

<!DOCTYPE HTML PUBLIC...
...
<body onload="runcode()">

Function runcode()
    if not (IsEmpty(Session("MM_Username"))) then
        Set checkSet = Server.CreateObject("ADODB.Recordset")
        checkSet.ActiveConnection = MM_CA_STRING
        checkSet.Source = "SELECT * FROM cpgdb.dbo_tbl_printing_tempstore WHERE username = '" & Session("MM_username") & "' AND addedtocart = 'NO'"
        checkSet.Open()

    end if
End Function

我试图通过简单地复制 <% code %> 并将其粘贴在 Function - End Function 之间来将此代码移动到函数中。这不起作用 - 语法看起来不正确。有人可以告诉我为什么以及我需要进行哪些调整才能使其正常工作,以及 onload 事件是否会满足我的需要?

任何帮助表示赞赏。

4

1 回答 1

0

不幸的是,您所要求的在 VBScript/ASP 中是不可能的。VBScript/ASP 是一种服务器端编程语言,您正试图使用​​它来诱导客户端行为。如果你想做这样的事情,你必须用 Javascript 或设置“元刷新”值:

<meta http-equiv="cache-control" content="no-cache"> <!-- tells browser not to cache -->

<meta http-equiv="expires" content="0"> <!-- says that the cache expires 'now' -->

<meta http-equiv="pragma" content="no-cache"> <!-- says not to use cached stuff, if there is any -->
于 2012-02-11T19:12:31.527 回答