[英]How to call a VBScript from javascript
I found a small script on https://www.webdeveloper.com/d/49920-how-to-call-a-javascript-from-vbscript/5 that says you call simply call a VB script function in JavaScript. 它還舉了這個例子:
<HTML>
<Head>
</head>
<Script Language=JavaScript>
function callVB(){
setTimeout(function(){KeepAwake();}, 5000);
}
</Script>
<Script Language=VBScript>
Function KeepAwake()
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{ENTER}"
End Function
</Script>
<Body>
<input type=button value="Call VB" onclick="callVB()">
</Body>
</HTML>
它工作得很好。 5 秒后按回車鍵。 所以我把它放在我自己的代碼中。 hta 說盡管 VBS 代碼相同,但 VBS function 未定義。 錯誤信息
我玩了一段時間,但它仍然無法正常工作,我能找到的所有互聯網都是我正在做的事情。
我究竟做錯了什么?
這是我自己的代碼
<!DOCTYPE html>
<html>
<head>
<title>The Amazing Nanny Helper</title>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script>
</head>
<p id="retrunValue"></p>
<label for="myfile" id="label" name="label">Select a file:</label>
<input type="file" id="myfile" name="myfile" multiple>
<label for="Start">Start Row:</label>
<input type="number" id="Start" min="0">
<button type="button" onclick="do5();">Do 5</button>
<button type="button" onclick="do25();">Do 25</button>
<button type="button" onclick="do100();">Do 100</button>
<button type="button" onclick="do1000();">Do 1000</button>
<button type="button" onclick="do10000();">Do 10000</button>
<Script Language=JavaScript>
//A bunch of unimportant functions
function do5() {
FileInput(5);
}
function do25() {
FileInput(25);
}
function do100() {
FileInput(100);
}
function do1000() {
FileInput(1000);
}
function do10000() {
FileInput(10000);
}
function FileInput(times) {
KeepAwake(); // attempt to call VBS function
// Big loop driven by setTimeouts and functions calling functions that call the calling function
}
//A few more unimportant functions
</Script>
<Script Language=VBScript>
Function KeepAwake()
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{ENTER}"
End Function
</Script>
</body>
</html>
問題出在這個標簽上:
<meta http-equiv="x-ua-compatible" content="ie=edge" />
在這里你 state 內容應該使用最新的可用 IE 引擎運行。 該選擇顯然不支持 VBScript。 您可以獲得對 VBScript 的支持,其值如下:
<meta http-equiv="x-ua-compatible" content="ie=ie11" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.