Nov 17
Every modern browser provides the ability to search for text within a page. In most cases that functionality is underserved and allows you to find only one instance of the text at a time. Google Chrome recently presented improved version of search which searches for the given text as you type and highlights all instances found on the current page. But wait a minute: is this functionality limited to Google Chrome only?
Check out my article @ End User SharePoint.com: “Search on this Page” using jQuery
















December 10th, 2008 at 10:25 pm
It's an interesting feature, one that I'd love to use but, alas, I am (for once) crippled by mac and can't use chrome at the moment
December 10th, 2008 at 11:56 pm
@James: I have created a JavaScript equivalent of the Google Chrome search highlight. You can use the JavaScript in any browser.
January 13th, 2009 at 4:23 pm
Waldek,
I really love your site – it's an abounding source of know how and tips. I tested the demo of this script on endusersharepoint.com and it would only work when I entered one search term in the box. Any ideas why it would not work once a space is entered? 'Lorem ipsum' should definitely be found…
January 13th, 2009 at 10:01 pm
@Christoph: Thank you for the feedback, Christoph. I appreciate it. As for your question: I believe that the problem has to do with the regular expression which runs the search. I think that the regex engine doesn't recognize spaces as valid characters and would rather expect \s (which could be of course replaced on-the-fly but somehow slipped my mind
).
August 25th, 2009 at 8:45 am
Hello Waldek,
I want to use this library in my open source project, but it isn\'t clear what license your code was released under (I\'m assuming public domain since you included it in a tutorial).
If there isn\'t a particular license attached to the code, will the following file header be sufficient attribution? Thanks.
<pre>
/*
\"Search on this Page\" plugin for jQuery by
Waldek Mastykarz <http://blog.mastykarz.nl>
Published online, on 17 November 2008, at
<http://www.endusersharepoint.com/?p=951> and
<http://blog.mastykarz.nl/search-page-jquery/>
This source code was extracted directly from this demo page:
<http://blog.mastykarz.nl/samples/jquery/searchOnThisPage.html>
*/
</pre>
August 25th, 2009 at 11:53 am
@Suraj: the header you've mentioned is okay with me. Please note, that by including the code in your custom solution you are the one responsible for it, meaning providing any fixes, support, etc.
Glad I could help!
March 31st, 2010 at 5:17 am
Hi
There are 2 main issues with this script.
1 – it searches within the HTML tags them selves, partially fixed with:
var htmls= $(this).html();
var text= $(this).text();
if(text.match(regx))
{
//original replacement code
}
That way it has to match the text and then replaces on the html – muuuch better but still not 100%
2) if the text wrapper matches multiple – the object only stores the original html for the first instance… fixed by:
// — public methods
this.resetOriginalText= function() {
var instance = this;
$(instance.textWrapper).each(function(i){$(this).html(instance.originalText[i]);});
}
and
this.setOriginalText= function() {
var instance=this;
$(".ms-vb,.ms-vb2").each(function(i){
instance.originalText[i]=$(this).html();
});
instance.set=true;
}
March 31st, 2010 at 5:18 am
OH – i forgot
var searchText = escape(this.value);
searchText=searchText.replace(/%20/gi,"\\s");
makes it search over spaces too.
March 31st, 2010 at 5:21 am
@tfforums: great suggestions. Thanks for the feedback.