【发布时间】: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