如何注入进入 WPF WebBrowser 控件以重叠其中的所有网页内容?
我想要做的是,当 WPF WebBrowser 加载页面时,我只想在页面内容上放置一些 以防止用户在下载的页面中发生任何点击事件。
所以这个想法是以某种方式将包含它的样式插入到下载的页面中......
可以这样做吗?
如果可以的话,那么如何用C#实现呢?
What I want to do is when WPF WebBrowser loads page I just want to put over page content some to prevent any click events from user within downloaded page.
So the idea is somehow insert that including it style into downloaded page...
Is it possible to do?
If yes, then how it could be implemented in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以导航到
javascript:
URL 吗?这可能是最便宜的方法,我相信这就是我过去最终所做的。还有另一种方法涉及直接访问 DOM。它涉及访问
WebBrowser.Document
,您可以将其转换为 COM 类型。我需要向您回复确切的技术 - 我已将其保存在某处 - 但在 MSDN。编辑:
测试 JavaScript 的最简单方法是执行以下操作:
如果出现一个对话框,显示
Test
且网页没有消失,则说明它有效。如果测试有效,您可以在那里插入任何您想要的 JavaScript。例如:正确的方法
我将尝试一下,但它尚未经过测试,因此请记住,您可能需要稍微调整此过程。
ShDocVw.dll
。mshtml
命名空间添加using
语句。WebBrowser.Document
对象转换为mshtml.IHTMLDocument2
接口。编辑:这个问题 有一些很好的例子。不过,我会使用普通转换而不是
as
关键字。obj as Something
是obj is Something 的语法糖? (某事)obj:null
。额外的测试在这里确实是不必要的。Can you navigate to a
javascript:
URL? That's probably the cheap way to do it, and I believe that's what I ended up doing in the past.There's another way involving directly accessing the DOM. It involves accessing
WebBrowser.Document
, which you can cast to a COM type. I'll need to get back to you on the exact technique--I have it saved somewhere--but there's a tiny bit of a hint on MSDN.Edit:
The easiest way to test the JavaScript would be to do something like:
If you get a dialog saying
Test
without your web page disappearing, it works. You can insert any JavaScript you want there, provided the test worked. For example:The Proper Way
I'm going to give this a shot, but it's untested, so keep in mind that you might need to tweak this process a bit.
ShDocVw.dll
.using
statement for themshtml
namespace.WebBrowser.Document
object to anmshtml.IHTMLDocument2
interface.Edit: This question has some good examples. I would use plain casting instead of the
as
keyword, though.obj as Something
is syntax sugar forobj is Something ? (Something)obj : null
. That extra test really is unnecessary here.