Reputation: 1
I am trying to intercept a click on the "view source" item on C# WebBrowser's context menu. The default click opens the web page's source in notepad, but I would like, to cancel the default action and open my own form with the source code in a RichTextBox, which is a part of the opening window.
Thanks to Robert I managed to intercept opening right-clicked links in new tabs instead of new windows (Open link in new TAB (WebBrowser Control)), but I was unable to capture the "view source" click.
I would appreciate any advices and solutions to my problem.
Thank you in advance :)
Upvotes: 0
Views: 1240
Reputation: 6453
Late reply, but one way to do it is to reference Microsoft.mshtml
and read the source like:
var doc = yourBrowserControl.Document.DomDocument as IHTMLDocument2;
txtSource.Text = doc.body.innerHTML;
However, this method does not give you the complete source (for example, the HEAD section of the source is completely missing).
Upvotes: 0