如何将 vbscript 复制到函数并在正文 onload 触发时运行它

发布于 2025-01-04 04:31:43 字数 1285 浏览 1 评论 0原文

我继承了一个主要是 vbscript/asp 的网站。一页有 <% vbscript %>在 DOCTYPE HTML PUBLIC... 行之前并在页面打开之前运行。即使用户按下另一个页面上的后退按钮才能到达那里,我也需要让它运行。大概通过将其放置一个 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 事件是否会执行我需要的操作吗?

任何帮助表示赞赏。

I've inherited a site which is mostly vbscript/asp. One page has <% vbscript %> before the DOCTYPE HTML PUBLIC... line and runs before the page opens. I need to get this to run even if the user presses the back button on another page to get there. Presumably by placing it an onload function - Is that correct?

This is a shortened piece of the <% %> code:

<%
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>

I think I need to get it to run like this:

<!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

I've tried to move this code into the function by simply copying the <% code %> and pasting it between the Function - End Function. This doesn't work - the syntax looks incorrect. Can someone please tell me why and what adjustments I need to make it work and also if the onload event will do what I need it to?

Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚你心 2025-01-11 04:31:43

不幸的是,您所要求的在 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 -->

Unfortunately what you're asking for is not possible in VBScript/ASP. VBScript/ASP is a server side programming language and you're trying to use it to induce client side behavior. If you want to do something like this, you'd have to do it in Javascript or set the "Meta Refresh" values:

<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 -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文