Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i call VBscript from Javascript

I have searched the threads here but could not find anything remotely related to what i am trying to do. Basically i want to call vbscript using javascript for the onClick.

Is there a way to call aVBScript for the onClick event from a button that uses Javascript onmouseover and onmouseout events?

I can't seem to get it to work and need help. Below is a snippet of my javascript code and also vb script i would like to call out to:

Javascript code:

<td align="center">
    <input onMouseOver="window.status=me.value" onMouseOut="window.status=''" onMouseOver="window.status=me.value" onMouseOut="window.status=''" type="button" value="Impersonation" class="redBtn" onClick="openPopup('http://internal.mps.cardinal.net/cardcom/index.asp')" />
   </td>
   <td align="center">
    <input onMouseOver="window.status=me.value" onMouseOut="window.status=''" onMouseOver="window.status=me.value" onMouseOut="window.status=''" type="button" value="ServiceNow" class="normalBtn" onClick="openPopup('https://cardinal.service-now.com/navpage.do')" />
   </td>

What i would like to do is call out to the vbscript for the ServiceNow OnClick event.

My VBscript: WScript.Quit Main

Function Main
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://cardinal.service-now.com/navpage.do"
Wait IE

With IE.Document
On Error Resume Next
  .GetElementsByName("EnterpriseID")(0).value = "admin"
  .GetElementsByName("PASSWORD")(0).value = "admin"
End With

IE.Document.getElementByID("SignInBtn").Click

End Function

Sub Wait(IE)
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy 
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy 
End Sub

Sub IE_OnQuit

On Error Resume Next WScript.StdErr.WriteLine "IE closed before script finished." WScript.Quit End Sub

Thank you for any help you can provide

like image 657
Drew Avatar asked Aug 01 '13 13:08

Drew


People also ask

Can JavaScript call VBScript function?

Javascript being a client side scripting language, and vb code is processed on the server, thus you cant call a vb/c# function from javascript.

How do I run a VBScript on a website?

To insert a VBScript into an HTML page, we use the <script> tag. Inside the <script> tag we use the type attribute to define the scripting language. The document. write command is a standard VBScript command for writing output to a page.

Can Chrome run VBScript?

VBScript does not support all modern browsers. VBScript is supported by Internet Explorer of Microsoft only, while other browsers (Firefox and Chrome) offer JavaScript support.


1 Answers

Yes you can do that, this sample uses onmouseover/out in JS and onClick in VBScript.

  <script type="text/vbscript">
      Function MyVbAlert()
        MsgBox("Hello from VB Script!")
      End Function
  </script>

   <script type="text/javascript">

       function myJsMouseOver(c) {
            c.style.color = 'green'    
       }

       function myJsMouseOut(c) {
           c.style.color = 'black'
       }

   </script>


    <span onclick="MyVbAlert()" onmouseover="myJsMouseOver(this)" onmouseout="myJsMouseOut(this)" >Click Me</span>
like image 192
Yuriy Galanter Avatar answered Oct 27 '22 01:10

Yuriy Galanter