是否可以检测 WP7 WebBrowser 控件中点击的 DOM 元素?
是否可以使用 WP7 WebBrowser 控件检测用户在网站上点击的位置下的 DOM 元素?我想让用户识别渲染页面的某些部分。
Is it possible to detect the DOM elements under a spot the user taps on a website using the WP7 WebBrowser control? I would like to let the user identify certain sections of the rendered page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。这段代码对我来说效果很好:
它符合贾斯汀的答案(他在编码时打败了我)。它首先定义一个单击处理程序,然后将其附加到页面的主体(全部通过
InvokeScript
)。每次点击某个元素时ScriptNotify
应该在WebBrowser
上调用,报告点击元素的标签名称。确保您已将浏览器控件的
IsScriptEnabled
设置为 true。Yes. This code works pretty well for me:
It goes along Justin's answer (who beat me while coding). It first defines a click handler which then is attached to the page's body (all via
InvokeScript
). Every time you tap an elementScriptNotify
should be called on theWebBrowser
reporting the tapped element's tag name.Make sure you have set
IsScriptEnabled
true for your browser control.我猜你必须构建一些东西 ScriptNotify 事件。
此时,您将照常注册一个 JavaScript 事件处理程序,但该事件处理程序将依次调用
window.external.notify("someMessageToHandle");
。然后,您必须适当地路由呼叫。如果您无法直接在页面上添加 JavaScript 事件处理程序,则可以使用 WebBrowserControl.InvokeScript。
I'm guessing you'd have to build something off of the ScriptNotify Event.
At that point, you would register a JavaScript Event handler as usual but that event handler would, in turn, call
window.external.notify("someMessageToHandle");
. You would then have to route the calls appropriately.If you don't have the ability to add the JavaScript event handlers directly on the page, you could instead add them using WebBrowserControl.InvokeScript.