【问题标题】:System.NotSupportedException when accessing a variable of IHtmlDocument2.Script in 32 bit outlook after a second navigate在第二次导航后访问 32 位 Outlook 中的 IHtmlDocument2.Script 变量时出现 System.NotSupportedException
【发布时间】:2019-04-04 11:13:02
【问题描述】:

我正在使用 VB .Net 在 Outlook 中开发一个插件,该插件使用 mshtml 界面在阅读窗格中查看一个 html 窗口。该页面有一些我使用 IHtmlWindow2.execScript 调用的 javascript 代码。我使用 IHtmlWindow2.navigate(url) 函数加载页面并通过执行以下操作访问一些 javascript 变量:

Dim htmlWindow As IHTMLWindow2
htmlWindow.execScript("x=somefunction();","javascript")
Dim result as String = htmlWindow.document.Script.x.ToString()

当我从 Outlook 64 位实例运行此代码时,它运行良好...从 Outlook 32 位实例运行插件(无论是在 32 位还是 64 位机器上),当我在 htmlWindow 上执行第二次导航后,它会给出 System.NotSupportedException,当我首先导航到 url 并执行此代码,它可以正常工作。

在outlook加载的页面上使用internet explorer调试器F12Chooser,下面的代码执行没有错误并返回所需的值。

x=somefunction();
window.document.Script.x;

但是,我尝试了一个突破点

htmlWindow.execScript("x=somefunction();","javascript")

并在 Visual Studio 的即时窗口中执行相同的代码,但每次导航后使用另一个变量名,我没有异常

htmlWindow.execScript("y=somefunction();","javascript")
MessageBox.Show(htmlWindow.document.Script.y.ToString())

我不理解这种行为,如果能提供任何帮助,我将不胜感激。我怀疑它与一些缓存有关,但我不知道在哪里,我在互联网上搜索了这个但没有成功。

【问题讨论】:

    标签: javascript vb.net outlook mshtml ihtmldocument2


    【解决方案1】:

    来自this MSDN page

    执行脚本

    注意 IHTMLWindow2::execScript 不再受支持。 从 IE11,使用eval。 有关信息,请参阅兼容性更改。

    以提供的语言执行指定的脚本。

    自从我涉足 Outlook 加载项以来已经有很长时间了,但看起来首选的方法是使用 eval 代替。我知道这可能不是您想听到的答案,但这就是我要开始的地方!

    【讨论】:

    • 即使在使用 eval 时,也不幸注意到相同的行为
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多