在 IE9 中不将任何内容从 Javascript 传递到 VBScript

发布于 2024-12-06 21:01:35 字数 1342 浏览 0 评论 0原文

我有一个用 VBScript 编写的框架。在该框架的某些函数内,会在 If 语句中检查该函数的参数是否为 Nothing,然后执行一些操作。

使用该框架的代码是用 JavaScript 编写的。所以我需要将Nothing传递给函数来执行一些操作。在 Internet Explorer 8 及更早版本中,以下方法有效:

<script type="text/vbscript">
    Function Test(val)
        If (IsNull(val)) Then
            Test = "Null"
        ElseIf (IsObject(val)) Then
            If (val Is Nothing) Then
                Test = "Nothing"
            End If
        End If
    End Function

    Dim jsNothing
    Set jsNothing = Nothing
    msgBox(Test(jsNothing))
    msgBox(Test(Null))
</script>


<script type="text/javascript">
    alert(Test(jsNothing));
</script>

在 Internet Explorer 之前的版本中9、输出将:Nothing、Null、Nothing。

Internet Explorer 9 中:无、空、空。

如何在 Internet Explorer 9 中将 JavaScript 中的 Nothing 传递给 VBScript?

有一个框架函数的例子。我无法更改它,因为它在应用程序中被广泛使用。

Function ExampleFunction(val)
    If (val Is Nothing) Then
        ExampleFunction = 1
    Else
        ExampleFunction = 0
    End If
End Function

I have a framework written in VBScript. Inside some function in this framework, a parameter of the function is checked for Nothing in an If statement and then some actions are executed.

Code that uses the framework is written in JavaScript. So I need to pass Nothing to the function to perform some actions. In Internet Explorer 8 and earlier versions, the following approach worked:

<script type="text/vbscript">
    Function Test(val)
        If (IsNull(val)) Then
            Test = "Null"
        ElseIf (IsObject(val)) Then
            If (val Is Nothing) Then
                Test = "Nothing"
            End If
        End If
    End Function

    Dim jsNothing
    Set jsNothing = Nothing
    msgBox(Test(jsNothing))
    msgBox(Test(Null))
</script>


<script type="text/javascript">
    alert(Test(jsNothing));
</script>

In Internet Explorer before version 9, the output will: Nothing, Null, Nothing.

In Internet Explorer 9: Nothing, Null, Null.

How can I pass Nothing from JavaScript to VBScript in Internet Explorer 9?

There is an example of a framework function. I can not change it, because it is widely used in application.

Function ExampleFunction(val)
    If (val Is Nothing) Then
        ExampleFunction = 1
    Else
        ExampleFunction = 0
    End If
End Function

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

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

发布评论

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

评论(4

东走西顾 2024-12-13 21:01:35

不幸的是,您可能被困在这里 - JavaScript 没有“Nothing”等价物。有关详细信息,请参阅本文

但是,以下方法可能有效。在 VBScript 代码中,创建一个名为“GetNothing”的函数,该函数返回“Nothing”。在 JavaScript 代码中,使用“var jsNothing = GetNothing()”。它来自这篇文章

Unfortunately, you are probably stuck here - JavaScript does not have a "Nothing" equivalent. See this article for more information.

However, the following may work. In your VBScript code, create a function called "GetNothing" that returns "Nothing". In your JavaScript code, use "var jsNothing = GetNothing()". It comes from this article.

烟酒忠诚 2024-12-13 21:01:35

我现在无法访问 Internet Explorer,所以我无法对此进行测试,但尝试编写这样的函数:

<script type="text/vbscript">
  Function CallWithNulls(fn, arg1, arg2, arg3)
    If (isNull(arg1)) arg1 = Nothing
    If (isNull(arg2)) arg2 = Nothing
    If (isNull(arg3)) arg3 = Nothing
    fn(arg1, arg2, arg3)
  End Function
  Function IsNothing(arg1, arg2, arg3)
     return arg1 is Nothing
  End Function
</script>

<script type="text/javascript">
  alert(CallWithNulls(IsNothing, null, 1, 2));
</script>

当然,我不知道 VBScript 是否允许调用这样的函数...必须处理更多/更少的争论。

I don't have access to Internet Explorer right now, so I can't test this, but try to write a function like this:

<script type="text/vbscript">
  Function CallWithNulls(fn, arg1, arg2, arg3)
    If (isNull(arg1)) arg1 = Nothing
    If (isNull(arg2)) arg2 = Nothing
    If (isNull(arg3)) arg3 = Nothing
    fn(arg1, arg2, arg3)
  End Function
  Function IsNothing(arg1, arg2, arg3)
     return arg1 is Nothing
  End Function
</script>

<script type="text/javascript">
  alert(CallWithNulls(IsNothing, null, 1, 2));
</script>

Of course, I don't know if VBScript allows calling functions like that... and you'd have to deal with more/fewer arguments.

堇年纸鸢 2024-12-13 21:01:35

使用零甚至负数等值。这将允许您简单地使用虚假计算,然后您不必担心不同的浏览器及其在计算 NULL 对象时的怪癖。

Use a value such as zero or even a negative number. That would allow for you to simply use falsy evaluations, and then you don't have to worry about different browsers and their quirks in evaluating the NULL object.

神回复 2024-12-13 21:01:35

举个例子,这样的东西是可行的,但如果浏览器是 Internet Explorer 11 或稍后您将需要“meta”标签。

<html>

    <head>
        <meta http-equiv="x-ua-compatible" content="IE=10">
        <title>Pass JavaScript to VBScript</title>

        <script>
            var val = "null";

            window.alert("Test: " +  val);
        </script>

        <script type="text/vbscript">

            PassNothing(val)

            Sub PassNothing(value)
                If LCase(value) = "null" Then
                    MsgBox "Java passed 'null' so VBScript = 'Nothing'"
                Else
                    Msgbox "Nothing received"
                End If
            End Sub

        </script>

    </head>

</html>

As an example, something like this will work, but if the browser is Internet Explorer 11 or later you will need the 'meta' tag.

<html>

    <head>
        <meta http-equiv="x-ua-compatible" content="IE=10">
        <title>Pass JavaScript to VBScript</title>

        <script>
            var val = "null";

            window.alert("Test: " +  val);
        </script>

        <script type="text/vbscript">

            PassNothing(val)

            Sub PassNothing(value)
                If LCase(value) = "null" Then
                    MsgBox "Java passed 'null' so VBScript = 'Nothing'"
                Else
                    Msgbox "Nothing received"
                End If
            End Sub

        </script>

    </head>

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