Skip to content Skip to sidebar Skip to footer

Access Vbscript Variable Within Javascript Inside Of An Hta

I'm trying to access a variable in javascript that i set in vbscript all within one hta file:

Solution 1:

Based on your question, I've written an HTA containing the following code:

<scripttype="text/vbscript">
dim globalvariable
globalvariable = "test123"</script><scripttype="text/javascript">
alert(globalvariable);
</script>

and the value "test123" is displayed in the alert box.

Note the following differences with your code:

  • vbs language syntax is different to js syntax;
  • your js code looks like asp code to me, rather than js;
  • I got an error message using '' without 'text/' prefix;

Solution 2:

Mixing languages in a .HTA App is easy, if you just follow the syntactical rules for each language (e.g. there is no "var" in VBScript).

<html><head><hta:applicationid = "mix"></hta><scriptLANGUAGE="VBScript">Dim gsX : gsX = "global VBScript variable"</script><scriptLANGUAGE="JScript">
  alert(gsX);
  </script></head><body></body></html>

Solution 3:

Can you use a DOM element like a hidden input field to communicate between VBScript and JS? If that works you can trigger a custom event when the value changes, and listen for that event on both sections.

I never used VBScript before so this may not be possible.

Post a Comment for "Access Vbscript Variable Within Javascript Inside Of An Hta"