【问题标题】:Invoke ActiveXobject via java script - object undefined error通过 javascript 调用 ActiveX 对象 - 对象未定义错误
【发布时间】:2015-07-30 21:40:02
【问题描述】:

全部,

我有一个 java 脚本文件,它打开一个记事本文件但出现未定义对象错误。我觉得这与安全有关,但不确定.. 可以请教吗?

注意:单击按钮时调用运行函数。 错误:未捕获的 ReferenceError:未定义 ActiveXObject 在 IE 中 - 我能够收到警报 4,但看不到记事本,但在 Chrome 中只能卡在警报 1。

<script language="JavaScript" type="text/javascript">
    function run() {
        alert("step 1");
        var oShell;
        oShell = new ActiveXObject("Shell.Application");
        alert("step 2");
        var commandtoRun = "c:\\windows\\system32\\notepad.exe";
        alert("step 3");
        oShell.ShellExecute(commandtoRun, "", "", "open", "1");
        alert("step 4");
    }
</script>

【问题讨论】:

  • Microsoft's own documentationCreating an ActiveXObject on a remote server is not supported in Internet Explorer 9 standards mode, Internet Explorer 10 standards mode, Internet Explorer 11 standards mode, and Windows Store apps or later.
  • 在 Chrome 中 - 因为其他浏览器不支持 ActiveXObject,您会卡在 alert1 上。
    在 IE 中 - 你卡在 alert4 - 因为你的浏览器没有运行 exe 的权限。您收到权限被拒绝错误。

标签: javascript activexobject


【解决方案1】:

ActiveXObject 是 Microsoft 的专有功能,除 Internet Explorer 之外的任何浏览器均不支持。

其他网络浏览器在任何情况下都不允许网页运行任意程序。

【讨论】:

  • 谢谢!明白了...不过一个查询...至少在 IE 中,我应该能够打开记事本?如果我能够看到第 4 步警报?我做错了什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多