admin管理员组文章数量:1404603
I am writing an HTA and I need to pass a variable that I have in Javascript to a VBScript function. Can you please let me know how to do this? Here is a (nonworking) example of what I'm trying to do:
<!DOCTYPE ... >
<html>
<head>
<HTA:APPLICATION ID="chrome" APPLICATIONNAME="kiosk" ... />
...
<script type="text/javascript">
...
var closer = "C:\Program Files";
...
</script>
<script language="VBScript" src="close.vbs"></script>
</head>
<body>
<a href="#" onClick="VBScript:CloseExplorerWindow(window.closer)">close</a>
</body>
</html>
Please bear in mind that this example is waaaay oversimplified - I've just tried to strip out all the plexity and present you with what it is I'm actually trying to do.
Bonus: Is is possible to fire a VBScript function from a javascript one? My HTA uses jQuery quite extensively and it'd be nice to be able to do the system stuff I need to do from within jQuery.
I am writing an HTA and I need to pass a variable that I have in Javascript to a VBScript function. Can you please let me know how to do this? Here is a (nonworking) example of what I'm trying to do:
<!DOCTYPE ... >
<html>
<head>
<HTA:APPLICATION ID="chrome" APPLICATIONNAME="kiosk" ... />
...
<script type="text/javascript">
...
var closer = "C:\Program Files";
...
</script>
<script language="VBScript" src="close.vbs"></script>
</head>
<body>
<a href="#" onClick="VBScript:CloseExplorerWindow(window.closer)">close</a>
</body>
</html>
Please bear in mind that this example is waaaay oversimplified - I've just tried to strip out all the plexity and present you with what it is I'm actually trying to do.
Bonus: Is is possible to fire a VBScript function from a javascript one? My HTA uses jQuery quite extensively and it'd be nice to be able to do the system stuff I need to do from within jQuery.
Share Improve this question edited Jul 27, 2010 at 10:33 Andy E 345k86 gold badges481 silver badges451 bronze badges asked Jul 27, 2010 at 10:01 Iain FraserIain Fraser 6,7288 gold badges44 silver badges68 bronze badges2 Answers
Reset to default 4If a function is defined in VBScript, it can be executed from JavaScript as if it were any other globally available function. Both scripting languages share global variables and functions. I used to use a function so that I could access MsgBox from my JavaScript code using the following:
<script type="text/vbscript">
Function vbsMsgBox (prompt, buttons, title)
vbsMsgBox = MsgBox(prompt, buttons, title)
End Function
</script>
<script type="text/javascript">
vbsMsgBox("This is a test", 16, "Test");
</script>
The order of inclusion is important when mixing these scripts. If the first script on your page is vbscript, that bees the default scripting engine for event handlers. If the first is javascript, that would be the default. Providing vbscript:
or javascript:
is a mon misconception - in JavaScript a string followed by a colon indicates a label monly paired with loops and break/continue statements. In VBScript, it would just cause an error. This confusion stems with the method of running script from a URL, e.g. in the href of an <a>
element:
<a href="javascript:doSomething(); void(0);">do something</a>
With your sample code, assuming closer
is a global variable then your event handler should look like this:
<a href="#" onclick="CloseExplorerWindow(closer)">close</a>
Also, take a look at this MSDN article on using JScript and VBScript on the same page.
Your example should work, sure its not doing what you expect because var closer = "C:\Program Files";
should be var closer = "C:\\Program Files";
?
本文标签:
版权声明:本文标题:internet explorer - How do you pass a javascript variable as an argument to a vbscript function (in the context of HTAs)? - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744832514a2627434.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论