View Full Version : IE6 and small highlite script

07-04-2007, 03:46 PM
I needed something really simple that would highlite the results of a fulltext search in my asp.net application, and decided on javascript. I managed to get it working wuite well (despite the fact that im using a regular expression to keep out of html tags, which was tricky and the regexp sometimes misses a keyword, but it doesnt mess up my page so its all good)- well actually, it does mess up my page, but only, strictly on IE6... i havent tested 7 though... firefox (v2.0.0.4) wont even give me a warning or an error in the javascript error console, and I've used pretty much very simple javascript.

function HighliteKeywords(strSearch)
var keywords = new Array();
keywords = strSearch.split(' ');
var rng;
if (keywords.length >= 1)
var regEx = new RegExp('((<[^<]*>)+[^<]*)('+keywords[k]+')', "gi");
var form = document.getElementById('aspnetForm');
rng = form.innerHTML;
form.innerHTML = rng.replace(regEx, "$1<span style='color: #000000;font-weight:bold;background-color: #dddd00;'>$3</span>");

I'm passing the strSearch as a uery parameter and use Page.MasterPage.FindControl("body") so as to find the body and add the onload attribute to it, cuz IE didnt like me putting up the function call on the page PreRender by assigning it to a literal, either. So i got it working on IE, then changed a few things in my regular expression to cover the html tags and tested on firefox, and it works nickel... now i just tried it in IE6 again... BAM, I try to load the page, and it just seems like its stuck in an infinite loop and wont finish loading, neither can i do anything but click on the x in the top and try again.

sadly i dont have a link to share for this cuz im developping locally and only transferring when I know nothing will bug up dramatically, and thats a very annoying bug. Anyone's got an idea?

*edit* Heh... well I recompiled and it seems like its not doing it anymore... I didnt change anything either to the script or the basic layout of the page, all I,ve been working on is some data access so I'm really confused as to what couldve caused this. Could it be that some AJAX component conflict with the javascript or vice-versa?

07-05-2007, 12:39 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


<script language="JavaScript" type="text/javascript">
var zxcWordAry=[];

function zxcWords(zxcN){
var zxcnu=zxcN.childNodes.length;
for(var zxc0=0;zxc0<zxcnu;zxc0++) {
var zxcTxt=zxcN.firstChild.data;
var zxc=zxcN.removeChild(zxcN.firstChild);
zxcAry=zxcTxt.split(' ');
for(var zxc1=0;zxc1<zxcAry.length; zxc1++) {
var zxcT=document.createElement('SPAN');
var zxcTTxt=document.createTextNode(zxcAry[zxc1]+' ');
else {

function zxcFindTxt(zxctxt){
for (var zxc0=0;zxc0<zxcWordAry.length;zxc0++){



function zxcES(zxcele,zxcstyle,zxcp,zxctxt){
if (typeof(zxcele)=='string'){ zxcele=document.createElement(zxcele); }
for (key in zxcstyle){ zxcele.style[key]=zxcstyle[key]; }
if (zxcp){ zxcp.appendChild(zxcele); }
if (zxctxt){ zxcele.appendChild(document.createTextNode(zxctxt)); }
return zxcele;

<body onload="zxcWords(document.getElementById('test1'))">
<p id="test1" >
Some words
<input type="Button" value="Find 'Some'" onclick="zxcFindTxt('Some');" >
<input type="Button" value="Find 'words'" onclick="zxcFindTxt('words');" >