c# - Read .html#XXX and display it on a webbrowser -
I am writing readied HTML in the local, but these ".html" files are internally split, whose "File" HTML # xxxxx ". I am displaying these files on webbrowser, but not accepting the given path due to" # ". I am reading an appellate book, its chapters are internally" # "Parsed by I get for every chapter, y It is a division of itself and this division is marked by #.
This is an example of division
& Lt; / NavPoint & gt; & Lt; NavPoint id = "np-3" playOrder = "3" & gt; & Lt; NavLabel & gt; & Lt; Text & gt; Content & lt; / Text & gt; & Lt; / NavLabel & gt; & Lt; Content src = "@Public @ vhost @g @ Gutenberg @ html @ files @ 42,248 @ 42,248 hours @ 42,248-h-0.htm.html # pgepubid00002" /> & Lt; / NavPoint & gt; & Lt; / NavMap & gt; to display:
navpoint = toc.nav map [0]; String srcContent = navP.Src; WebBrowser1.Source = Path + srcContent After
I answer as clean as possible If you want to keep it, then I have completely written the answer again. I believe you need these steps:
-
Navigating and DocumentCompleted - named Subscribe to events code to parse the URL and an
# -
- to override the stored navigation and WebBrowser new clean URL without the anchor divided by anchor For example the variable
- after the document is loaded, find the element referenced by anchor and scroll it down
The result will probably look like this. Please note that this is not a copy and paste code, I want to tell you how you can work you need to modify this code for your needs!
Let's say that the URL requested under myfile.html # customAnchor webBrowser1.Navigating + = new Vebbraujhrnvigetingaeventhandlr (web browser 1_neeting); WebBrowser1.DocumentCompleted + = New web browserDownmappletedAventHandler (webbrowser1Decatable); Split string by private void webBrowser1_Navigating (object sender, WebBrowserNavigatingEventArgs e) {if (e.Url.Contains ( "#") {string [] urlParts = e.Url.Split ( '#'); // character string # NEWURL = UrlParts [0]; // = myFile.html _somePrivateField = urlParts [1]; // Customer web browser 1. navigate (new Uri (new URL));}} private void web browser 1 document completed (object sender, Vebbrojr document Involved Event ARGs e) {HTMLElementCollection element = this.webBrowser1.Document.Body.All; foreach (element in HtmlElement elements) {string nameAttribute = ele ment.GetAttribute ( "name"); if (string.IsNullOrEmpty (nameAttribute) & amp ;! & amp; nameAttribute == _somePrivateField) {element .ScrollIntoView (true); break;}}} Actually it has not tried, but I hope that this will help you solve your problem.
Comments
Post a Comment