Intro:
I m working on a C# WinForms + WebBrowser project.
I d like to do some processing upon a click on a hyperlink.
在这里,我是如何在超文本链接上用超文本文件对每一个超级链接进行点击的:
void webBrowser_DocumentCompleted( object sender, WebBrowserDocumentCompletedEventArgs e ) { HtmlElementCollection links = webBrowser.Document.Links; foreach ( HtmlElement link in links ) { link.Click += delegate { MessageBox.Show( "C# Click!" ); }; } }
The Problem:
The above code works well, but the problem is that I get side effects from javascript code which also performs some clicking action.
I learned the hard way that this problem comes in many shapes and forms..
Here s a not so obvious example of a jQuery action that makes life harder:
$(document).ready(function() {
$("a").click(function() {
alert("jQuery Click!");
});
});
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>>
</head>
<body>
<a href="#">Click Me!</a>
</body>
</html>
<html>
<body>
这里发生的情况是,在<代码>WebBrowser控制”中点击超链接时,“jery Click”首先会消失,而且只有在“C# Click”电文被丢弃之后才能显示。
The Question:
I ve searched far and wide, but didn t yet come up with an answer.
我怎么能用“C#-programmatically”来防止在网上浏览器上实施j Query或任何其他形式的javascript代码?
Clarification:
I d like to say I already tried to alter the document in many ways, e.g. stripping <script>
tags from webBrowser.DocumentText
, and from the inner html node, and by working with HtmlElement
and the underlying IHtmlElement
objects...
但无uck。
更改<代码>webBrowser.DocumentText 造成文件重载体,因此,我失去我到原址的任何全权证书(例如厨师)。 改写的<代码>IHtmlElement,物体确实起作用,致使 j本已经装上,我再次无法阻止事件的发生。