最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

servicenow - How can i call VBscript from Javascript - Stack Overflow

programmeradmin6浏览0评论

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('.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('.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 ".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

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/card/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./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./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

Share Improve this question edited Nov 11, 2016 at 23:10 Jarrod Weaver 393 bronze badges asked Aug 1, 2013 at 13:46 DrewDrew 1131 gold badge1 silver badge7 bronze badges 12
  • <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('internal.mps.cardinal/card/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('cardinal.service-now./navpage.do')" /> </td> – Drew Commented Aug 1, 2013 at 13:48
  • 1 ewww.... people still use VBScript in the browser??? Why would you do such a thing? – Spudley Commented Aug 1, 2013 at 13:50
  • @Spudley legacy code? – Yuriy Galanter Commented Aug 1, 2013 at 13:50
  • @Drew - please edit the question and put the code there, not in a ment. It's unreadable in the ments. – Spudley Commented Aug 1, 2013 at 13:51
  • @Drew -- if that's an answer, can you please post it as an answer so you can get credit -- and people can read it! – Ernest Friedman-Hill Commented Aug 1, 2013 at 13:51
 |  Show 7 more ments

2 Answers 2

Reset to default 6

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>

I know this is old but I was looking for a way to call legacy VBScript from newer pages written with javascript. I used something like:

<script language="javascript" type="text/javascript">
function clickProxy() {
    document.getElementById("vbProxy").click(); // initiate click event on the button
}
</script>

<script language="vbscript" type="text/vbscript">
function runVB()
    msgbox "VBScript!"
end function
</script>

And then in the HTML:

<input type="button" id="vbProxy" onclick="vbscript: runVB" value="VB Proxy" style="height:0px;width:0px"/>
<input type="button" onclick="clickProxy()" value="Click Me" style="height:0px;width:0px"/>

DOM elements can see both javascript and vbscript, so I used one button to trigger a "proxy" button, which in turn calls the VBScript. You could even pass params (sort of) by dropping them into hidden input fields.

I didn't test the above, so apologies if there are any mistakes, but you get the idea!

发布评论

评论列表(0)

  1. 暂无评论