简体   繁体   中英

How to capture context menu “view source” click in c# WebBrowser control?

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 :)

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM