可能重复。
我想编写可以在 firefox 中执行 linux 命令的 javascript(似乎不可能,但希望问)
通过google,发现IE可以通过“ActiveXObject”。
这里是示例代码:
<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
function executeCommands(inputparms)
{
// Instantiate the Shell object and invoke
its execute method.
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Winnt\\Notepad.exe";
if (inputparms != "")
{
var commandParms = document.Form1.filename.value;
}
// Invoke the execute method.
oShell.ShellExecute(commandtoRun, commandParms,
"", "open", "1");
}
</SCRIPT>
那么,在 mozilla 应用程序的 javascript 中是否有任何等效的 ActiveXObject? 我是 javascript 的新手,所以请纠正错误。
谢谢!
最佳答案
在 Firefox 附加组件中,您可以使用 nsIProcess .沿着这些线的东西:
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\Winnt\\Notepad.exe");
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(file);
process.runAsync(["c:\\file.txt"]);
当然,此 API 只能由特权代码访问。
关于javascript - 使用javascript在firefox浏览器中评估系统命令或python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7687399/