Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call javascript function from vbscript

how to call javascript function from vbscript. i wrote like this

<script type="text/vbscript">
jsfunction()
</script>
<script type="text/javascript">
function jsfunction()
{
  alert("Hello")
}
</script>

but it is showing that type mis match how to achieve it. please help me.

Thank you, Mihir

like image 768
Mihir Avatar asked Dec 03 '22 08:12

Mihir


2 Answers

Assuming you want this client side as opposed to ASP;

If you place the JScript block before the VBScript block (or wire the call to a load event) that will work fine. (IE only of course)

...
<head>

<script type="text/vbscript">
     function foo
         call jsfunction()
     end function
</script>

<script type="text/javascript">
     function jsfunction()
     {
       alert("hello");
     }
</script>

</head>

<body onload="foo()">
...
like image 191
Alex K. Avatar answered Jan 13 '23 17:01

Alex K.


Calling a VBScript function from Javascript Your VBScript:

Function myVBFunction()
  ' here comes your vbscript code
End Function

Your Javascript:

function myJavascriptFunction(){
  myVBFunction();           // calls the vbs function
}
window.onload = myJavascriptFunction;
Alternatives (incompatible in some IE versions):


  // This one:
window.onload = function(){ myVBFunction(); }
  // This will also work:
window.onload = myVBFunction();
  // Or simply:
myVBFunction(); 
  // From a hardcoded link, don't write a semicolon a the end:
<a href="#" onclick="VBscript:myVBFunction('parameter')">link</a>    

Inversed: Calling a Javascript function from VBScript

Function myVBFunction()
  myJavascriptFunction()  
End Function
like image 42
bulevardi Avatar answered Jan 13 '23 15:01

bulevardi