ActiveX 仅在激活 IE 9 控制台时工作

ActiveX only working when IE 9 Console is activated

本文关键字:控制台 工作 IE 激活 ActiveX      更新时间:2023-09-26

我正在构建一个小型Web应用程序,该应用程序需要通过ActiveX和Javascript(以及IE9...)访问Powerpoint以自动构建报告。我正在使用ActiveX,因为我无法在服务器端生成Powerpoint文件(尽管我非常喜欢这个)。

我现在的代码非常简陋,因为我刚刚开始:

// Creating the ActiveX Powerpoint control
var ppt;
try{
    ppt = new ActiveXObject("Powerpoint.Application");
}catch(e){
    if (e instanceof ReferenceError)
        alert("Your browser might not be compatible with this function. Please use Internet Explorer.");
    else
        alert("An error happened: " + e);
}
console.log("ActiveX Object created");
// Openning Powerpoint, make it visible
ppt.Visible = 1;
// Creating a new Presentation, and adding a blank (1 slide, 1 = ppLayoutBlank) Slide
ppt.Presentations.Add();
ppt.ActivePresentation.Slides.Add(1, 1);

在我的计算机上,碰巧ActiveX控件无法启动Powerpoint,即使我允许它通过"An ActiveX control on this page might be dangerous; Do you allow it to execute?"执行(直接从法语中翻译)。

但是,如果我启动开发人员控制台,它会神奇地运行。而且,在另一台装有 IE 11 的计算机上,在我允许执行 ActiveX 控件后,它工作正常。

我认为我的IE安全设置是正确的,因此我想不出我不知道的IE故障的任何其他内容。我正在使用 IE 9.0.8112.16421 64 位。

我怎样才能让这段代码运行良好?提前谢谢你!

提醒:IE 中的console.log仅在开发人员控制台打开时有效。如果开发人员控制台关闭,它会停止脚本,因为console undefined

在代码中,尝试更改:

console.log("ActiveX Object created");

try{console.log("ActiveX Object created")}catch(err){}或注释该行://