new ActiveXObject(“InternetExplorer.Application”) 缺少 window.document 对象

发布于 2024-12-23 09:13:01 字数 1567 浏览 1 评论 0原文

我对这段代码有一个奇怪的问题。基本上,我加载一个新的 ActiveXObject(“InternetExplorer.Application”)并将对其的引用放到 IE 窗口对象上。然后,我加载一个 HTML 文件并等待它完成加载,然后再尝试在新窗口中运行脚本。当我通过 VS2010 启动 IE(带或不带调试(即 F5 或 CTRL-F5))时,此代码有效,并且我获得了对 lDebugWindow.document.documentElement 对象的引用。

问题——但是当我刚从 WIN7 任务栏启动 IE 时,lDebugWindow.document 总是未定义。你知道从 VS2010 启动 IE 与从任务栏启动 IE 有什么不同吗?下面是突出显示的行的代码,其行为与 VS2010 和 IE 任务栏启动不同:

function wfDebugXml(pNode)
{
    window.lDebugWindow = new ActiveXObject("InternetExplorer.Application");
    lDebugWindow.navigate(sFrameworkBase + "/GlobalDebugger/Debug.htm");

    lReady = false;

    for (var i = 0; i < 40; i++)
    {
        if (!lReady)
        {
            try
            {
                lDebugWindow.onreadystatechange = wfDebugRenderXml(pNode);
            }
            catch (e) { };
        }
    }
}

function wfDebugRenderXml(pNode)
{
    // THE NEXT LINE IS THE ONE THAT HAS THE PROBLEM
    var lDocumentElement = lDebugWindow.document.documentElement;

    var lXsltDoc = Sarissa.getDomDocument();
    lXsltDoc.async = false;
    lXsltDoc.load("GlobalDebugger/Debug.xsl");

    var lXslt = new XSLTProcessor();
    lXslt.importStylesheet(lXsltDoc);

    var lXmlDoc = Sarissa.getDomDocument();
    lXmlDoc.loadXML(pNode.xml);

    var lXmlOutput = lXslt.transformToFragment(lXmlDoc, lDebugWindow.document);

    while (lDocumentElement.childNodes.length > 0)
    {
        lDocumentElement.removeChild(lDocumentElement.lastChild);
    }

    lDocumentElement.appendChild(lXmlOutput);
    lDebugWindow.Visible = true;

}

I have a weird problem with this code. Basically I am loading a new ActiveXObject ("InternetExplorer.Application") and putting a reference to it onto the IE window object. I then load up an HTML file and wait for it to finish loading before trying to run script against the new window. When I launch IE via VS2010 with or without debugging (i.e. F5 or CTRL-F5) this code works and I get a reference to lDebugWindow.document.documentElement object.

The problem -- But when I just launch IE from the WIN7 taskbar, lDebugWindow.document is always undefined. Any ideas what is different about IE when launched from VS2010 versus the taskbar? Here is the code with the line highlighted that behaves differently from VS2010 vs. taskbar launch of IE:

function wfDebugXml(pNode)
{
    window.lDebugWindow = new ActiveXObject("InternetExplorer.Application");
    lDebugWindow.navigate(sFrameworkBase + "/GlobalDebugger/Debug.htm");

    lReady = false;

    for (var i = 0; i < 40; i++)
    {
        if (!lReady)
        {
            try
            {
                lDebugWindow.onreadystatechange = wfDebugRenderXml(pNode);
            }
            catch (e) { };
        }
    }
}

function wfDebugRenderXml(pNode)
{
    // THE NEXT LINE IS THE ONE THAT HAS THE PROBLEM
    var lDocumentElement = lDebugWindow.document.documentElement;

    var lXsltDoc = Sarissa.getDomDocument();
    lXsltDoc.async = false;
    lXsltDoc.load("GlobalDebugger/Debug.xsl");

    var lXslt = new XSLTProcessor();
    lXslt.importStylesheet(lXsltDoc);

    var lXmlDoc = Sarissa.getDomDocument();
    lXmlDoc.loadXML(pNode.xml);

    var lXmlOutput = lXslt.transformToFragment(lXmlDoc, lDebugWindow.document);

    while (lDocumentElement.childNodes.length > 0)
    {
        lDocumentElement.removeChild(lDocumentElement.lastChild);
    }

    lDocumentElement.appendChild(lXmlOutput);
    lDebugWindow.Visible = true;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转角预定愛 2024-12-30 09:13:01

我想你的问题现在已经消失了。对于其他人来说,这可能是一个正确的访问问题:
Win7下IE运行在低完整性进程中。我想可能无法在具有不同完整性级别的进程之间获取 COM 指针。

我使用 ChangeWindowMessageFilter 来解决我的问题,但我是通过消息进行通信的。不过,开始谷歌搜索可能是一个好时机。

I suppose your problem is gone now. For anyone else, it might be a right access issue :
Under Win7 IE runs in a low integrity processus. I suppose it might not be possible to get COM pointers between processus with different levels of integrity.

I used ChangeWindowMessageFilter to fix my issue but I was communicating via messages. It might be a good point to start Googling though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文