Example:
http://www.rodsdot.com/ee/
You will need to beef that up a bit so you do not try to highlight items inside form fields, etc., but slicing and concatenating strings in JavaScript is fast. Plus you have no worrys about what you are writing to the browser window with response.write and what is existant in HTML.
Regards,
Rod
Main Topics
Browse All Topics





by: rdivilbissPosted on 2005-03-25 at 09:00:22ID: 13631366
String functions, especially concatenation are very costly operations with ASP.
>var searchTerms='"& searchTerms &"';</scr"&"ipt>"
r';
{ ); dx++) an>'+tmpBo dy[jdx]; mp;
ms();</scr ipt>
It would seem quickest to do this client side, understanding of course, some small percentage of users will not receive the benefit of the highlighted words.
From ASP, assuming you have a comma delimited list of search terms in a variable called searchTerms;
response.write("<scr"&"ipt
Then add the following JavaScript function:
<script language="javascript" type="text/javascript">
<!--
var searchTerms='system,browse
function highlightSearchTerms(){
var temp = document.body.innerHTML;
var st=searchTerms.split(',');
var tmpBody;
for (var idx=0;idx<st.length;idx++)
tmpBody=temp.split(st[idx]
temp=tmpBody[0];
for (var jdx=1;jdx<tmpBody.length;j
temp+='<span class="st">'+st[idx]+'</sp
}
document.body.innerHTML=te
}
//-->
</script>
Add style to suit;
<style>
<!--
.st { font-weight: bold; background-color: #DEFA7E }
-->
</style>
finally add this between </body> and </html>
<script>highlightSearchTer