<?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: Search and highlight text in UIWebView</title>
	<atom:link href="http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/</link>
	<description>iCab related stuff; Mac, iPhone and Cocoa programming</description>
	<lastBuildDate>Sat, 25 May 2013 06:41:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-61587</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sun, 12 May 2013 10:12:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-61587</guid>
		<description><![CDATA[@John
Sorry for the delay, your comment was stuck in the SPAM filter…

If you want to highlight only one of the occurrences of the search term, and move the highlighting back and forward between all of the occurrences, you can do this as well. iCab Mobile is doing something like this as well: though it highlights all occurrences in yellow at the same time, you can jump between these occurrences and the current one if highlighted in another color.

What must be done here is to save all occurrences in an array while searching. And when you want to highlight item n, then just execute the &quot;highlight code&quot; from above for this one item. If you jump to another item, use the &quot;unhighlight code&quot; to remove the highlighting of the previous item and execute the highlight code for the new item again.]]></description>
		<content:encoded><![CDATA[<p>@John<br />
Sorry for the delay, your comment was stuck in the SPAM filter…</p>
<p>If you want to highlight only one of the occurrences of the search term, and move the highlighting back and forward between all of the occurrences, you can do this as well. iCab Mobile is doing something like this as well: though it highlights all occurrences in yellow at the same time, you can jump between these occurrences and the current one if highlighted in another color.</p>
<p>What must be done here is to save all occurrences in an array while searching. And when you want to highlight item n, then just execute the &#8220;highlight code&#8221; from above for this one item. If you jump to another item, use the &#8220;unhighlight code&#8221; to remove the highlighting of the previous item and execute the highlight code for the new item again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-61580</link>
		<dc:creator>John</dc:creator>
		<pubDate>Wed, 08 May 2013 10:42:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-61580</guid>
		<description><![CDATA[Hi Alexander,
It works Great.....  but problem is, when it got a string which appearing at multiple places in the para.  then get highlighted at every places...so what i want is...  highlighting of the words with the audio itself. Kind of like the bouncing ball that bounces from one word to another.


Thanks.]]></description>
		<content:encoded><![CDATA[<p>Hi Alexander,<br />
It works Great&#8230;..  but problem is, when it got a string which appearing at multiple places in the para.  then get highlighted at every places&#8230;so what i want is&#8230;  highlighting of the words with the audio itself. Kind of like the bouncing ball that bounces from one word to another.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-61397</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Fri, 08 Feb 2013 21:10:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-61397</guid>
		<description><![CDATA[@Paul Linsay
Yes, you can always make the code smarter ;-)

For example you can check if the element in which the text was found is one of those elements, which are never shown (like all elements within the HEAD section of the page), or if these elements have a CSS property &quot;display&quot; or &quot;visibility&quot; set to a value which makes the element invisible. For the latter use the function &quot;getComputedStyle()&quot; which also takes the inheritance of CSS properties into account...
&lt;pre&gt;
  if (window.getComputedStyle(element, false).display == &#039;none&#039;  &#124;&#124;
      window.getComputedStyle(element, false).visibility == &#039;hidden&#039;) {
     // element is not visible
  }
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>@Paul Linsay<br />
Yes, you can always make the code smarter <img src='http://www.icab.de/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>For example you can check if the element in which the text was found is one of those elements, which are never shown (like all elements within the HEAD section of the page), or if these elements have a CSS property &#8220;display&#8221; or &#8220;visibility&#8221; set to a value which makes the element invisible. For the latter use the function &#8220;getComputedStyle()&#8221; which also takes the inheritance of CSS properties into account&#8230;</p>
<pre>
  if (window.getComputedStyle(element, false).display == 'none'  ||
      window.getComputedStyle(element, false).visibility == 'hidden') {
     // element is not visible
  }
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Linsay</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-61396</link>
		<dc:creator>Paul Linsay</dc:creator>
		<pubDate>Fri, 08 Feb 2013 19:54:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-61396</guid>
		<description><![CDATA[I should have added that iCab doesn&#039;t find the invisible instance of code either ;-)]]></description>
		<content:encoded><![CDATA[<p>I should have added that iCab doesn&#8217;t find the invisible instance of code either <img src='http://www.icab.de/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Linsay</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-61395</link>
		<dc:creator>Paul Linsay</dc:creator>
		<pubDate>Fri, 08 Feb 2013 16:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-61395</guid>
		<description><![CDATA[Alexander, thanks for your hard work.  This is a great help for the iOS app I&#039;m developing, especially since I&#039;m a real novice at js.

I came across a problem that I don&#039;t know how to solve.  A keyword can be hiding in elements that aren&#039;t displayed on the web page.  When the user steps through the keywords he shouldn&#039;t have steps where nothing appears.  Apple is very smart about this and somehow avoids the hidden keywords.

As an example, go to the link

http://www.azleg.state.az.us/FormatDocument.asp?inDoc=/ars/47/01101.htm&amp;Title=47&amp;DocType=ARS

and search for &quot;code&quot;.  There are actually three instances of it but only two are visible.  If you click on More Agencies &gt; Executive you will see the bottom item in the dropdown menu is &quot;Admin Code&quot;.  Your little algorithm finds this but Apple&#039;s doesn&#039;t, either in Safari or mobile Safari. 

Any ideas on how to solve this would be appreciated.  Thanks again.]]></description>
		<content:encoded><![CDATA[<p>Alexander, thanks for your hard work.  This is a great help for the iOS app I&#8217;m developing, especially since I&#8217;m a real novice at js.</p>
<p>I came across a problem that I don&#8217;t know how to solve.  A keyword can be hiding in elements that aren&#8217;t displayed on the web page.  When the user steps through the keywords he shouldn&#8217;t have steps where nothing appears.  Apple is very smart about this and somehow avoids the hidden keywords.</p>
<p>As an example, go to the link</p>
<p><a href="http://www.azleg.state.az.us/FormatDocument.asp?inDoc=/ars/47/01101.htm&#038;Title=47&#038;DocType=ARS" rel="nofollow">http://www.azleg.state.az.us/FormatDocument.asp?inDoc=/ars/47/01101.htm&#038;Title=47&#038;DocType=ARS</a></p>
<p>and search for &#8220;code&#8221;.  There are actually three instances of it but only two are visible.  If you click on More Agencies &gt; Executive you will see the bottom item in the dropdown menu is &#8220;Admin Code&#8221;.  Your little algorithm finds this but Apple&#8217;s doesn&#8217;t, either in Safari or mobile Safari. </p>
<p>Any ideas on how to solve this would be appreciated.  Thanks again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-58476</link>
		<dc:creator>john</dc:creator>
		<pubDate>Sat, 19 Jan 2013 06:30:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-58476</guid>
		<description><![CDATA[Wanted to say big thanks for writing this blog post and for answering everyone&#039;s questions!!!  And thanks to JC for writing a followup on how he took your suggestion on search prev/next.]]></description>
		<content:encoded><![CDATA[<p>Wanted to say big thanks for writing this blog post and for answering everyone&#8217;s questions!!!  And thanks to JC for writing a followup on how he took your suggestion on search prev/next.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nilesh Tripathi</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-42139</link>
		<dc:creator>Nilesh Tripathi</dc:creator>
		<pubDate>Fri, 16 Nov 2012 14:39:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-42139</guid>
		<description><![CDATA[Okay ...  Thanks to demmy.. I copied his code and its working...

Thank you dammy and Alexander.]]></description>
		<content:encoded><![CDATA[<p>Okay &#8230;  Thanks to demmy.. I copied his code and its working&#8230;</p>
<p>Thank you dammy and Alexander.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-42132</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Fri, 16 Nov 2012 13:55:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-42132</guid>
		<description><![CDATA[@Nilesh Tripathi
Unfortunately, because of the limiting API of UIWebView, you  have no other choice than using JavaScript for almost everything you want to do that is not just loading a new web page. And doing this on the iPhone is a real pain, because there&#039;s no debugger and other help for debuggin the JavaScript code. 

JavaScript is able to get the selected text as raw text but also as a &quot;range&quot; object, which includes the first and last nodes which are covered by the text and also the offsets within these text nodes so you know exactly where exactly with these text nodes, the selection starts. Based on this information you can process the text and nodes depending of your requirements, but this can be complicated. The range can span many different block and inline elements and when manipulating the HTML code you may need to take care about the HTML structure as well. So you not only need to know much about JavaScript, but also much about HTML as well.

Highlighting a text the user has selected can be easy (when the text is completely inside a single text node) and you only need to add a new SPAN element like it is shown in this blog post, but it can also be extremly complicated (when the selected text spans multiple block and inline nodes). In this case you might have to create multiple SPAN elements in many of the involved nodes, make sure that inline and block element boundaries are preserved to avoid that the HTML code structure gets invalid and the layout of the page is destroyed.]]></description>
		<content:encoded><![CDATA[<p>@Nilesh Tripathi<br />
Unfortunately, because of the limiting API of UIWebView, you  have no other choice than using JavaScript for almost everything you want to do that is not just loading a new web page. And doing this on the iPhone is a real pain, because there&#8217;s no debugger and other help for debuggin the JavaScript code. </p>
<p>JavaScript is able to get the selected text as raw text but also as a &#8220;range&#8221; object, which includes the first and last nodes which are covered by the text and also the offsets within these text nodes so you know exactly where exactly with these text nodes, the selection starts. Based on this information you can process the text and nodes depending of your requirements, but this can be complicated. The range can span many different block and inline elements and when manipulating the HTML code you may need to take care about the HTML structure as well. So you not only need to know much about JavaScript, but also much about HTML as well.</p>
<p>Highlighting a text the user has selected can be easy (when the text is completely inside a single text node) and you only need to add a new SPAN element like it is shown in this blog post, but it can also be extremly complicated (when the selected text spans multiple block and inline nodes). In this case you might have to create multiple SPAN elements in many of the involved nodes, make sure that inline and block element boundaries are preserved to avoid that the HTML code structure gets invalid and the layout of the page is destroyed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nilesh Tripathi</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-42117</link>
		<dc:creator>Nilesh Tripathi</dc:creator>
		<pubDate>Fri, 16 Nov 2012 12:28:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-42117</guid>
		<description><![CDATA[This tutorial is a kind of that I cannot just walk away without saying “Thank you”. Appreciated your effort for putting this up.]]></description>
		<content:encoded><![CDATA[<p>This tutorial is a kind of that I cannot just walk away without saying “Thank you”. Appreciated your effort for putting this up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nilesh Tripathi</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-42111</link>
		<dc:creator>Nilesh Tripathi</dc:creator>
		<pubDate>Fri, 16 Nov 2012 11:51:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-42111</guid>
		<description><![CDATA[Hey Alexander

I want  a snippet to highlight a particular text which have been selected by user in UIWebView. 
I am using AEPubreader which have same functions for search and highlight that you have provided. 
Please help me out with. Basically I am an iPhone app developer, but no idea of javascript so I am little bit confused with it.
Thanks in advance.]]></description>
		<content:encoded><![CDATA[<p>Hey Alexander</p>
<p>I want  a snippet to highlight a particular text which have been selected by user in UIWebView.<br />
I am using AEPubreader which have same functions for search and highlight that you have provided.<br />
Please help me out with. Basically I am an iPhone app developer, but no idea of javascript so I am little bit confused with it.<br />
Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-39143</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sun, 28 Oct 2012 20:52:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-39143</guid>
		<description><![CDATA[@AppPear
Within the comments someone said that UIWebView will convert RTF to HTML, in which case this should work. But this is not documented by Apple and might also not be true for all iOS releases. So in general I would assume that the search feature would only work with HTML, for all other file formats, you may have luck, but there&#039;s no guarantee.]]></description>
		<content:encoded><![CDATA[<p>@AppPear<br />
Within the comments someone said that UIWebView will convert RTF to HTML, in which case this should work. But this is not documented by Apple and might also not be true for all iOS releases. So in general I would assume that the search feature would only work with HTML, for all other file formats, you may have luck, but there&#8217;s no guarantee.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AppPear</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-39140</link>
		<dc:creator>AppPear</dc:creator>
		<pubDate>Sun, 28 Oct 2012 20:30:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-39140</guid>
		<description><![CDATA[Hi!
Is there a way to work this awesome feature when uiwebview contains an rtf file?]]></description>
		<content:encoded><![CDATA[<p>Hi!<br />
Is there a way to work this awesome feature when uiwebview contains an rtf file?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-37255</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sun, 07 Oct 2012 17:31:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-37255</guid>
		<description><![CDATA[@sefiroths
Yes, in viewDidLoad the code is most likely not yet loaded. UIWebView loads everything in the background, so the only way to find out when the code is loaded is by implementing the UIWebView delegate method &quot;webViewDidFinishLoad:&quot;. This method is called when the HTML code is loaded.]]></description>
		<content:encoded><![CDATA[<p>@sefiroths<br />
Yes, in viewDidLoad the code is most likely not yet loaded. UIWebView loads everything in the background, so the only way to find out when the code is loaded is by implementing the UIWebView delegate method &#8220;webViewDidFinishLoad:&#8221;. This method is called when the HTML code is loaded.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sefiroths</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-37254</link>
		<dc:creator>sefiroths</dc:creator>
		<pubDate>Sun, 07 Oct 2012 17:06:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-37254</guid>
		<description><![CDATA[you can delete the previous post, i putted the code to hilight in viewdidload, perhaps the page was not loaded yet, if i put it in a button the code works well, thanks]]></description>
		<content:encoded><![CDATA[<p>you can delete the previous post, i putted the code to hilight in viewdidload, perhaps the page was not loaded yet, if i put it in a button the code works well, thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sefiroths</title>
		<link>http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/comment-page-6/#comment-37253</link>
		<dc:creator>sefiroths</dc:creator>
		<pubDate>Sun, 07 Oct 2012 16:58:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=110#comment-37253</guid>
		<description><![CDATA[hi, i&#039;ve tried this, seems wondeftul tutorial. but i&#039;m facing a problem:
i have a webview in storyboard, connected to iboutlet. i followed all steps but this does not hilight anytning...
putting nslog everywhere, seems that:
NSLog(@&quot;%@&quot;,path);&lt;----i can see the path
NSLog(jsCode);&lt;----i see javascript code
NSLog(@&quot;%@&quot;,[self stringByEvaluatingJavaScriptFromString:jsCode]);&lt;-- is not log anything...
[self stringByEvaluatingJavaScriptFromString:startSearch];&lt;---not log anything
any ideas?
if you want i can zip a project and put it on some file sharing site
thanks]]></description>
		<content:encoded><![CDATA[<p>hi, i&#8217;ve tried this, seems wondeftul tutorial. but i&#8217;m facing a problem:<br />
i have a webview in storyboard, connected to iboutlet. i followed all steps but this does not hilight anytning&#8230;<br />
putting nslog everywhere, seems that:<br />
NSLog(@&#8221;%@&#8221;,path);&lt;&#8212;-i can see the path<br />
NSLog(jsCode);&lt;&#8212;-i see javascript code<br />
NSLog(@&quot;%@&quot;,[self stringByEvaluatingJavaScriptFromString:jsCode]);&lt;&#8211; is not log anything&#8230;<br />
[self stringByEvaluatingJavaScriptFromString:startSearch];&lt;&#8212;not log anything<br />
any ideas?<br />
if you want i can zip a project and put it on some file sharing site<br />
thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
