【发布时间】:2018-09-02 10:53:29
【问题描述】:
为什么以下示例不起作用?另外,我想在createEmptyFile() 函数中隐藏 cmd.exe 的窗口。浏览器可能不应该阻止此代码:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Default Page Title</title>
</head>
<body>
<script type="text/javascript" language="javascript">
function pingItjs(ipAddress) {
var oShell = new ActiveXObject("wscript.shell");
oShell.Run("cmd.exe /k ping" + ipAddress);
}
function createEmptyFile() {
var oShell = new ActiveXObject("wscript.shell");
oShell.Run("cmd.exe /c cd %tmp% && echo hello > EmptyFile");
}
</script>
<script language="VBScript">
function pingIt(ipAddress)
set WshShell = CreateObject("WScript.Shell")
WshShell.Run("cmd.exe /k ping " & ipAddress)
end function
</script>
<a href="javascript:pingItjs('216.58.215.78')">ping</a>
<div onclick="call pingIt('216.58.215.78')">ping</div>
<a href="javascript:createEmptyFile()">ping</a>
</body>
</html>
【问题讨论】:
-
你用什么浏览器测试?
ActiveXObjects 仅在 IE 11 和 Edge 中受支持 -
我用firefox测试过,所以只有
VBScript可以解决这个问题。 -
我是说 IE 6+ 和 Edge
标签: javascript vbscript