我想从我的网页 (HTML) 打开 cmd 窗口。我正在使用 JS,但有些地方不对,因为当我按下时,函数没有被调用。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
<!--
function runCmd(command, option)
{
var char34 = String.fromCharCode(34);
var wsh = new ActiveXObject('WScript.Shell');
if (wsh)
{
command = 'cmd /k ' + char34 + wsh.ExpandEnvironmentStrings(command) + ' ';
command = command + char34 + wsh.ExpandEnvironmentStrings(option) + char34 + char34;
if (confirm(command))
{
wsh.Run(command);
}
}
}
//-->
</script>
</head>
<body>
<input type="button" value="Run!" onclick="runCmd(‘notepad.exe’, ‘%programfiles%\file.txt’);" />
</body>
</html>
编辑: 我将它保存为 PHP,现在我在 FF 中遇到错误:
ActiveXObject is not defined
[Break on this error] var wsh = new ActiveXObject('WScript.Shell');
谢谢!
最佳答案
您基本上必须关闭浏览器中的所有安全功能(需要某种类型的 Internet Explorer 才能使用 ActiveX)。
大多数浏览器都不允许这种事情,您能想象如果 [互联网上的随机人] 只需让您访问网页就可以在您的计算机上运行他们想要的任何东西吗?
关于javascript - 从浏览器运行 cmd - 通过 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4215339/