在HTA内的Javascript中访问VBScript变量 [英] Access VBScript variable within Javascript inside of an HTA
问题描述
我正在尝试访问我在vbscript中设置的javascript中的变量,这些变量都在一个hta文件中:
I'm trying to access a variable in javascript that i set in vbscript all within one hta file:
<script type="vbscript">
var globalVariable = test123
</script>
<script type="text/javascript">
var globalVariable = <%= globalVariable %>;
</script>
这不会在变量globalVariable中填充任何内容.我也尝试过
This doesn't populate the variable globalVariable with anything. I've also tried
var globalVariable = "<%= globalVariable %>";
这只是将引号中的字符串填充到变量globalVariable中.
This just populates the string within the quotes into the variable globalVariable.
我无法在VBScript部分中设置的值'test123
'填充到JS部分中的JS变量中.
I can't get the value 'test123
' set in the VBScript section to populate into a JS variable within the JS section.
任何帮助将不胜感激.
推荐答案
根据您的问题,我编写了包含以下代码的HTA:
Based on your question, I've written an HTA containing the following code:
<script type="text/vbscript">
dim globalvariable
globalvariable = "test123"
</script>
<script type="text/javascript">
alert(globalvariable);
</script>
,警报框中将显示值"test123".
and the value "test123" is displayed in the alert box.
请注意以下与代码的区别:
Note the following differences with your code:
- vbs语言语法与js语法不同;
- 您的js代码对我来说就像是asp代码,而不是js;
- 我收到的错误消息是使用带有'text/'前缀的';
这篇关于在HTA内的Javascript中访问VBScript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!