在 IE9 中不将任何内容从 Javascript 传递到 VBScript
我有一个用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是,您可能被困在这里 - 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.
我现在无法访问 Internet Explorer,所以我无法对此进行测试,但尝试编写这样的函数:
当然,我不知道 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:
Of course, I don't know if VBScript allows calling functions like that... and you'd have to deal with more/fewer arguments.
使用零甚至负数等值。这将允许您简单地使用虚假计算,然后您不必担心不同的浏览器及其在计算
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.举个例子,这样的东西是可行的,但如果浏览器是 Internet Explorer 11 或稍后您将需要“meta”标签。
As an example, something like this will work, but if the browser is Internet Explorer 11 or later you will need the 'meta' tag.