<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Highlight words in webbrowser control</title>
	<atom:link href="http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/</link>
	<description>Wrecks of code floating in the sea of Internet</description>
	<lastBuildDate>Mon, 06 Sep 2010 12:34:55 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: FERNANDO LOPEZ</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-3115</link>
		<dc:creator>FERNANDO LOPEZ</dc:creator>
		<pubDate>Tue, 25 May 2010 21:18:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-3115</guid>
		<description>HighLight Results in WebBrowser Control for WPF ...

I nedd to do a little variation of this code to make it works in WPF, here is the code:

1- I need to add the reference: Microsoft.mshtml (solution explorer / Referenes)

2- add using mshtml;

3-  code for the event LoadCompleted (wbContenido = WebBrowser control)

private void wbContenido_LoadCompleted(object sender, NavigationEventArgs e)
        {
            mshtml.HTMLDocumentClass dom = (mshtml.HTMLDocumentClass)wbContenido.Document;
            //Console.Write(dom.body.innerHTML);

            IHTMLDocument2 doc2 = dom;// wbContenido.Document.DomDocument as IHTMLDocument2;
            StringBuilder html = new StringBuilder(doc2.body.outerHTML);

            var words = new[] { &quot;Examen&quot;, &quot;passione&quot; };
            foreach (String key in words)
            {
                String substitution = &quot;&quot; + key + &quot;&quot;;
                html.Replace(key, substitution);
            }

            doc2.body.innerHTML = html.ToString();
        }</description>
		<content:encoded><![CDATA[<p>HighLight Results in WebBrowser Control for WPF &#8230;</p>
<p>I nedd to do a little variation of this code to make it works in WPF, here is the code:</p>
<p>1- I need to add the reference: Microsoft.mshtml (solution explorer / Referenes)</p>
<p>2- add using mshtml;</p>
<p>3-  code for the event LoadCompleted (wbContenido = WebBrowser control)</p>
<p>private void wbContenido_LoadCompleted(object sender, NavigationEventArgs e)<br />
        {<br />
            mshtml.HTMLDocumentClass dom = (mshtml.HTMLDocumentClass)wbContenido.Document;<br />
            //Console.Write(dom.body.innerHTML);</p>
<p>            IHTMLDocument2 doc2 = dom;// wbContenido.Document.DomDocument as IHTMLDocument2;<br />
            StringBuilder html = new StringBuilder(doc2.body.outerHTML);</p>
<p>            var words = new[] { &#8220;Examen&#8221;, &#8220;passione&#8221; };<br />
            foreach (String key in words)<br />
            {<br />
                String substitution = &#8220;&#8221; + key + &#8220;&#8221;;<br />
                html.Replace(key, substitution);<br />
            }</p>
<p>            doc2.body.innerHTML = html.ToString();<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alkampfer</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2929</link>
		<dc:creator>alkampfer</dc:creator>
		<pubDate>Mon, 01 Feb 2010 15:41:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2929</guid>
		<description>Doing what you want is just a matter of creating a javascript that is able to do this. But it seems not simple to me. The javascript functino I used was taken from a third party blog. 

Alk.</description>
		<content:encoded><![CDATA[<p>Doing what you want is just a matter of creating a javascript that is able to do this. But it seems not simple to me. The javascript functino I used was taken from a third party blog. </p>
<p>Alk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff T.</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2928</link>
		<dc:creator>Jeff T.</dc:creator>
		<pubDate>Mon, 01 Feb 2010 10:18:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2928</guid>
		<description>I did your code above and it worked for me. My Question is, can i use outertext instead of outerhtml from the body so that i can highlight those text inside a html tag. like inside an &quot;A&quot; element. Sample is

&quot;This is a &lt;a href=&quot;www.sample.com&quot; rel=&quot;nofollow&quot;&gt; HighLight Me &lt;/a&gt; please sample&quot;.

My search word is &quot;This is a HighLight Me please sample&quot; and this should match the above exampe and ignoring the html element.</description>
		<content:encoded><![CDATA[<p>I did your code above and it worked for me. My Question is, can i use outertext instead of outerhtml from the body so that i can highlight those text inside a html tag. like inside an &#8220;A&#8221; element. Sample is</p>
<p>&#8220;This is a <a href="www.sample.com" rel="nofollow"> HighLight Me </a> please sample&#8221;.</p>
<p>My search word is &#8220;This is a HighLight Me please sample&#8221; and this should match the above exampe and ignoring the html element.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alkampfer</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2880</link>
		<dc:creator>alkampfer</dc:creator>
		<pubDate>Sat, 09 Jan 2010 11:41:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2880</guid>
		<description>Converting to VB.Net should not be a difficult task, but I suggest you to use my other approach listed in this post http://www.codewrecks.com/blog/index.php/2009/03/11/hilite-words-in-webbrowser-now-for-wpf-control/ that uses a javascript hiliter. 

Alk.</description>
		<content:encoded><![CDATA[<p>Converting to VB.Net should not be a difficult task, but I suggest you to use my other approach listed in this post <a href="http://www.codewrecks.com/blog/index.php/2009/03/11/hilite-words-in-webbrowser-now-for-wpf-control/" rel="nofollow">http://www.codewrecks.com/blog.....f-control/</a> that uses a javascript hiliter. </p>
<p>Alk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hekmat</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2871</link>
		<dc:creator>Hekmat</dc:creator>
		<pubDate>Thu, 07 Jan 2010 07:20:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2871</guid>
		<description>Please convert this code to vb.net !</description>
		<content:encoded><![CDATA[<p>Please convert this code to vb.net !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alkampfer</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2703</link>
		<dc:creator>alkampfer</dc:creator>
		<pubDate>Mon, 05 Oct 2009 22:42:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2703</guid>
		<description>The problem with this kind of code, is that we manipulate directly the DOM in a very harsh way. As an example that code replaces key even inside tag, and sometimes this completely destroy the html page. The main problem is that you need an html parser to avoid HTML structure corruption.

A better solution I found, as I said before, was switching to an alreaady tested javascript function to hilite text. 

To reverse hiliting the best way is to save the original content of the page, and when you need to remove hilighting you simply reassign old content to the innerHTML property.

alk.</description>
		<content:encoded><![CDATA[<p>The problem with this kind of code, is that we manipulate directly the DOM in a very harsh way. As an example that code replaces key even inside tag, and sometimes this completely destroy the html page. The main problem is that you need an html parser to avoid HTML structure corruption.</p>
<p>A better solution I found, as I said before, was switching to an alreaady tested javascript function to hilite text. </p>
<p>To reverse hiliting the best way is to save the original content of the page, and when you need to remove hilighting you simply reassign old content to the innerHTML property.</p>
<p>alk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alkampfer</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2699</link>
		<dc:creator>alkampfer</dc:creator>
		<pubDate>Mon, 05 Oct 2009 12:23:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2699</guid>
		<description>As soon as possibile I&#039;ll post a working sample, it seems that everything is ok, so I&#039;ll try your code to understand what is wrong.

alk.</description>
		<content:encoded><![CDATA[<p>As soon as possibile I&#8217;ll post a working sample, it seems that everything is ok, so I&#8217;ll try your code to understand what is wrong.</p>
<p>alk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rani</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2695</link>
		<dc:creator>Rani</dc:creator>
		<pubDate>Sat, 03 Oct 2009 19:02:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2695</guid>
		<description>private void RealBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //Watch list
            KeywordManager keys = new KeywordManager();
            string[] words = keys.GetKeywordList();
            try
            {

                mshtml.HTMLDocument doc2 = (mshtml.HTMLDocument)RealBrowser.Document.DomDocument;
                StringBuilder html = new StringBuilder(doc2.body.outerHTML);

                foreach (String key in words)
                {
                    String substitution = &quot;&quot; + key + &quot;&quot;;
                    html.Replace(key, substitution);

                    doc2.body.innerHTML = html.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

i use this and when i click on the highlighted HTML link it is not working</description>
		<content:encoded><![CDATA[<p>private void RealBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)<br />
        {<br />
            //Watch list<br />
            KeywordManager keys = new KeywordManager();<br />
            string[] words = keys.GetKeywordList();<br />
            try<br />
            {</p>
<p>                mshtml.HTMLDocument doc2 = (mshtml.HTMLDocument)RealBrowser.Document.DomDocument;<br />
                StringBuilder html = new StringBuilder(doc2.body.outerHTML);</p>
<p>                foreach (String key in words)<br />
                {<br />
                    String substitution = &#8220;&#8221; + key + &#8220;&#8221;;<br />
                    html.Replace(key, substitution);</p>
<p>                    doc2.body.innerHTML = html.ToString();<br />
                }<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                MessageBox.Show(ex.Message);<br />
            }<br />
        }</p>
<p>i use this and when i click on the highlighted HTML link it is not working</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alkampfer</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2582</link>
		<dc:creator>alkampfer</dc:creator>
		<pubDate>Thu, 16 Jul 2009 13:35:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2582</guid>
		<description>Actually I used a javascript to hilite words as you can see in this post http://www.nablasoft.com/alkampfer/index.php/2009/03/11/hilite-words-in-webbrowser-now-for-wpf-control/ it works better than this example.</description>
		<content:encoded><![CDATA[<p>Actually I used a javascript to hilite words as you can see in this post <a href="http://www.nablasoft.com/alkampfer/index.php/2009/03/11/hilite-words-in-webbrowser-now-for-wpf-control/" rel="nofollow">http://www.nablasoft.com/alkam.....f-control/</a> it works better than this example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexandros</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2581</link>
		<dc:creator>Alexandros</dc:creator>
		<pubDate>Wed, 15 Jul 2009 14:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2581</guid>
		<description>nice and simple . a simple step further to go seems to put a simple button and a textbox for search

this is the code for the button
       
        private void button8_Click(object sender, EventArgs e)
        {
            //if containts &gt;1 word
            if(searchKeywords.Length &gt; 0)
            {
                //reverse the highlighted keywords if it only worked!!
                foreach(string keyword in searchKeywords)
                {
                    var temp_str = &quot;&quot; + keyword + &quot;&quot;;
                    webBrowser1.DocumentText = webBrowser1.DocumentText.Replace(temp_str, keyword);
                }
                webBrowser1.Invalidate();
            }
            //the textbox may have many word divided by char space                       
            var keywords = textBox2.Text.Split(&#039; &#039;);
            //grab the values for use to reverse highlighting
            searchKeywords = keywords;

             //highlight search keywords in webbroswer control
             foreach (string keyw in keywords)
             {
                 //MessageBox.Show(index.ToString());
                 webBrowser1.DocumentText = webBrowser1.DocumentText.Replace(keyw, @&quot;&quot;+keyw+&quot;&quot;);
             }
             //control repaint
             webBrowser1.Invalidate();
           
        }

but the reversing of highlighting doesn&#039;t work . what do you think?</description>
		<content:encoded><![CDATA[<p>nice and simple . a simple step further to go seems to put a simple button and a textbox for search</p>
<p>this is the code for the button</p>
<p>        private void button8_Click(object sender, EventArgs e)<br />
        {<br />
            //if containts &gt;1 word<br />
            if(searchKeywords.Length &gt; 0)<br />
            {<br />
                //reverse the highlighted keywords if it only worked!!<br />
                foreach(string keyword in searchKeywords)<br />
                {<br />
                    var temp_str = &#8220;&#8221; + keyword + &#8220;&#8221;;<br />
                    webBrowser1.DocumentText = webBrowser1.DocumentText.Replace(temp_str, keyword);<br />
                }<br />
                webBrowser1.Invalidate();<br />
            }<br />
            //the textbox may have many word divided by char space<br />
            var keywords = textBox2.Text.Split(&#8216; &#8216;);<br />
            //grab the values for use to reverse highlighting<br />
            searchKeywords = keywords;</p>
<p>             //highlight search keywords in webbroswer control<br />
             foreach (string keyw in keywords)<br />
             {<br />
                 //MessageBox.Show(index.ToString());<br />
                 webBrowser1.DocumentText = webBrowser1.DocumentText.Replace(keyw, @&#8221;"+keyw+&#8221;");<br />
             }<br />
             //control repaint<br />
             webBrowser1.Invalidate();</p>
<p>        }</p>
<p>but the reversing of highlighting doesn&#8217;t work . what do you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hilite words in webbrowser now for WPF control</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2126</link>
		<dc:creator>Hilite words in webbrowser now for WPF control</dc:creator>
		<pubDate>Wed, 11 Mar 2009 10:24:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2126</guid>
		<description>[...] Some days ago, I blogged about how to hilite words in a webBrowser control for windows forms. Now I need to do the same thing on WPF WebBrowser control, but instead of doing direct modification of DOM, a friend suggested me a Javascript script to hilite words in document. My original technique, discussed in old post, is not so good because it replaces text in the whole content of the document, and sometimes it breaks script etc. Now I need to put everything in WPF and here is how you can accomplish the task. [...]</description>
		<content:encoded><![CDATA[<p>[...] Some days ago, I blogged about how to hilite words in a webBrowser control for windows forms. Now I need to do the same thing on WPF WebBrowser control, but instead of doing direct modification of DOM, a friend suggested me a Javascript script to hilite words in document. My original technique, discussed in old post, is not so good because it replaces text in the whole content of the document, and sometimes it breaks script etc. Now I need to put everything in WPF and here is how you can accomplish the task. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gayner</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2093</link>
		<dc:creator>Gayner</dc:creator>
		<pubDate>Wed, 25 Feb 2009 06:04:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2093</guid>
		<description>double quote is disappear, so it shows the \\

string substitution =  + text.ToString() + ;</description>
		<content:encoded><![CDATA[<p>double quote is disappear, so it shows the \\</p>
<p>string substitution =  + text.ToString() + ;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gayner</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2092</link>
		<dc:creator>Gayner</dc:creator>
		<pubDate>Wed, 25 Feb 2009 06:01:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2092</guid>
		<description>Hello! I&#039;m using the C# language, I have tried your coding and convert it into C#.

My program haven&#039;t run the code in documentcompleted eventhandler

when it step to the first statement (HtmlDocument abc = (HtmlDocument)webBrowser1.Document.DomDocument;
), it step out

Can you tell me which part i have caused the problem?

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlDocument abc = (HtmlDocument)webBrowser1.Document.DomDocument;
            StringBuilder html = new StringBuilder(abc.Body.OuterHtml);

            string text = \school\;

            string substitution = \\ + text.ToString() + \\;

            html.Replace(text.ToString(), substitution);

            abc.Body.InnerHtml = html.ToString();
        }</description>
		<content:encoded><![CDATA[<p>Hello! I&#8217;m using the C# language, I have tried your coding and convert it into C#.</p>
<p>My program haven&#8217;t run the code in documentcompleted eventhandler</p>
<p>when it step to the first statement (HtmlDocument abc = (HtmlDocument)webBrowser1.Document.DomDocument;<br />
), it step out</p>
<p>Can you tell me which part i have caused the problem?</p>
<p>private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)<br />
        {<br />
            HtmlDocument abc = (HtmlDocument)webBrowser1.Document.DomDocument;<br />
            StringBuilder html = new StringBuilder(abc.Body.OuterHtml);</p>
<p>            string text = \school\;</p>
<p>            string substitution = \\ + text.ToString() + \\;</p>
<p>            html.Replace(text.ToString(), substitution);</p>
<p>            abc.Body.InnerHtml = html.ToString();<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: background &#187; Blog Archive &#187; Highlight words in webbrowser control</title>
		<link>http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/comment-page-1/#comment-2080</link>
		<dc:creator>background &#187; Blog Archive &#187; Highlight words in webbrowser control</dc:creator>
		<pubDate>Sat, 14 Feb 2009 00:00:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2009/02/13/highlight-words-in-webbrowser-control/#comment-2080</guid>
		<description>[...] Background/History: wrote an interesting post today onHere&#8217;s a quick excerptDomDocument as IHTMLDocument2; StringBuilder html = new StringBuilder(doc2.body.outerHTML); var words = new[] { &#8220;laureati&#8221;, &#8220;passione&#8221; }; foreach (String key in words) { String substitution = &#8220; [...]</description>
		<content:encoded><![CDATA[<p>[...] Background/History: wrote an interesting post today onHere&#8217;s a quick excerptDomDocument as IHTMLDocument2; StringBuilder html = new StringBuilder(doc2.body.outerHTML); var words = new[] { &#8220;laureati&#8221;, &#8220;passione&#8221; }; foreach (String key in words) { String substitution = &#8220; [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
