对于使用XMLHttpRequest更改其内容的页面,合适的事件侦听器是什么?

What is the appropriate event listener for a page that change its content using XMLHttpRequest?
2020-11-21
  •  译文(汉语)
  •  原文(英语)

通过在C#中使用GeckoWebBrowser,是否可以知道页面何时完成使用XMLHttpRequest更新其内容?我以为DocumentCompleted事件会做到这一点,但由于该页面没有重新加载,因此不会启动...

速聊1:
"...当页面完成使用XMLHttpRequest更新其内容时..." XMLHttpRequest不会修改网页.JavaScript代码可能会响应XHR请求的完成.
解决过程1

您可以使用变异观察者观察document.body的子树,并假设在收到最后一条通知后20毫秒,页面已完成修改(例如).

在JavaScript中,如下所示:

速聊1:
太完美了...感谢您的快速回答!
速聊2:
-注意:MutationObserver要求IE11或更高版本.
速聊3:
:他在C#中使用GeckoWebBrowser.(但是在IE9和IE10中,有些项目使用-ugh-突变事件来模拟MutationObserver.)
速聊4:
.J.Crowder在这种情况下,即使我必须以编程方式将代码段附加到文档中,该代码段也可以正常工作,这是我想的第一件事,但是还有另一种方法避免注入代码?
速聊5:
:我不明白这个问题.

By using the GeckoWebBrowser in C# is there anyway to know when a page has completed updating its content using XMLHttpRequest ? I thought that the DocumentCompleted event would have done it but since the page it's not reloading it wont fire up...

Talk1:
"...when a page has completed updating its content using XMLHttpRequest..." XMLHttpRequest doesn't modify web pages. JavaScript code might, in response to the completion of an XHR request.
Solutions1

You could use a mutation observer watching document.body's subtree, and assume that the page has finished being modified (say) 20ms after the last notification you get.

In JavaScript, that would look something like this:

Talk1:
It's just perfect... Thanks for the quick answer !
Talk2:
- Note: MutationObserver requires IE11 or above.
Talk3:
: He's using GeckoWebBrowser in C#. (But in IE9 and IE10, there are projects that emulate MutationObserver using -- ugh -- mutation events...)
Talk4:
.J.Crowder In the cases the page it's mine or not this snippet works perfectly even if in the second case I have to append the snippet to the document programmatically... That's the first thing that I thought, but is there another way to avoid injecting code ?
Talk5:
: I don't understand the question.
转载于:https://stackoverflow.com/questions/28397974/what-is-the-appropriate-event-listener-for-a-page-that-change-its-content-using

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入