我有一个带有一些参数(名称,电子邮件等)的VBScript,我创建了一个HTML表单。
当用户输入数据时,我想执行VBScript并将表单数据作为参数传递。
问题是如何从HTML表单运行VBScript(没有服务器,因此客户端执行HTML并在其计算机上运行VBscript)。
VBScript是一个外部文件。让我们称之为myScript.vbs
答案 0 :(得分:1)
我不知道HTML表单在没有HTTP连接的情况下“提交”数据到服务器的任何方式。以下是一些可以解决您问题的选项:
希望这有帮助!
答案 1 :(得分:1)
巧合的是,我昨天刚刚发布了一个问题,如何在Ruby中执行此操作,并将vbscript脚本作为示例,所以在这里你有了它。但事实上反过来最好,你最好从你的脚本启动浏览器。
Set web = CreateObject("InternetExplorer.Application")
If web Is Nothing Then
msgbox("Error while loading Internet Explorer")
Wscript.Quit
Else
with web
.Width = 300
.Height = 175
.Offline = True
.AddressBar = False
.MenuBar = False
.StatusBar = False
.Silent = True
.ToolBar = False
.Navigate "about:blank"
.Visible = True
end with
End If
'Wait for the browser to navigate to nowhere
Do While web.Busy
Wscript.Sleep 100
Loop
'Wait for a good reference to the browser document
Set doc = Nothing
Do Until Not doc Is Nothing
Wscript.Sleep 100
Set doc = web.Document
Loop
'Write the HTML form
doc.Write "Give me a name<br><form><input type=text name=name ><input type=button name=submit id=submit value='OK' onclick='javascript:submit.value=""Done""'></form>"
Set oDoc = web.Document
Do Until oDoc.Forms(0).elements("submit").Value <> "OK"
Wscript.Sleep 100
If web Is Nothing or Err.Number <> 0 Then
msgbox "Window closed"
Wscript.Quit
End If
Loop
name = oDoc.Forms(0).elements("name").value
oDoc.close
set oDoc = nothing
web.quit
set web = nothing
Wscript.echo "Hello " & name
答案 2 :(得分:0)
这是我的HTML代码
<form id="myform">
<input type="radio" name="formradio" id="yes" />
<input type="radio" name="formradio" id="no" />
<select name="formemail" size="1">
<option value="someone@example.com" selected="selected">someone@example.com</option>
</select>
<button type="submit" id="sendReport">Send Status Report</button>
这是我在HTML页面中的VBscript代码
<script language="VBScript" type="text/vbscript">
<![CDATA[
Sub sendReport_onclick()
'Logic to process the form goes in here.
MsgBox myform.formradio.value
MsgBox myform.formemail.value
'Run: wscript "{path}externalVBScript.vbs" "{path}"
WSHShell.Run "wscript """ & Path & "externalVBScript.vbs"" """ & Path & """"
window.status = "Script has been run via WScript"
End Sub
]]>
</script>