在 DocumentCompleted 被触发后检测 webBrowser 文档更改

发布于 2024-10-09 02:08:33 字数 195 浏览 0 评论 0原文

我正在使用 WebBrowser 控件。我编辑一些 HTML 输入并单击 WebBrowser DocumentCompleted 事件处理程序中的按钮。我的问题是单击我提到的按钮使用 AJAX 更改文档的内容,知道我需要从新更改中解析一些信息。问题是:如何检测文档何时完成加载新内容。是否有像 DocumentChanged 这样的事件处理程序?

提前致谢。

I am using a WebBrowser control. I edit some HTML inputs and click a button in the WebBrowser DocumentCompleted event handler. My problem is clicking the button I mentioned changes the content of the Document using AJAX, Knowing that I need to parse some information from the new changes. The question is: How can I detect when the document has finished loading the new content. Is there any sort of an event handler like DocumentChanged.

Thanks in advance.

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

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

发布评论

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

评论(3

再见回来 2024-10-16 02:08:33

我以为你会回来讨论这件事。可扩展性对象模型对于观察脚本执行没有很好的支持。这是不切实际的,脚本代码可以在不可预测的时间与页面状态完全异步运行。如果脚本没有做出可靠的 DOM 修改供您读回,那么除了转动轮子几秒钟以给其“足够的时间”之外,您没有其他更好的选择。考虑到您在工作线程中运行它,这应该不是问题,只需使用 System.Windows.Forms.Timer ,其 Tick 事件调用 Application.ExitThread 来结束线程。

I figured you'd be back about this. The extensibility object model has no great support for observing scripting execution. It isn't practical, scripting code can run completely asynchronous from the page state at unpredictable times. If there are no reliable DOM modifications made by the script that you can read back then you have no great options beyond just spinning your wheels for a couple of seconds to give it 'enough time'. Shouldn't be a problem given that you run this in a worker thread, just use a System.Windows.Forms.Timer who's Tick event calls Application.ExitThread to end the thread.

少女七分熟 2024-10-16 02:08:33

我确信没办法做到这一点 - WebBrowser 控件非常简单且功能很差

No way to do that, I'm sure - WebBrowser control is very simple and poor-functional

乖乖公主 2024-10-16 02:08:33

您可以控制所显示文档的 HTML 吗?如果是这样,在 ajax 更改完成后,您可以使用 Javascript 来调用父表单 window.external.MyPublicMethodName() 中的 C# 方法。您的应用程序需要在“完全信任”下运行才能正常工作,并且还需要在 Form_Load 事件中将浏览器 ObjectForScripting 对象设置为表单本身,例如 this.webBrowser1.ObjectForScripting = this;

Do you control the HTML of the document you're displaying ? If so, after the ajax changes have completed you can use Javascript to call a C# method in your parent form window.external.MyPublicMethodName() instead. Your app needs to be running in Full Trust for this to work, and also to have set the browser ObjectForScripting object to the form itself e.g. this.webBrowser1.ObjectForScripting = this; in your Form_Load event.

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