hi,
i have a javascript function to highlight google search keywords in the
page. it works well on IE and mozilla browsers. for the page OnLoad, i
call the Highlight() method, and that highlights the words in the page, and
inserts a div element with the message: "your search terms have been
highlighted..." and a link to remove the highlighting, which has
href='javascript:removeHighlight(..)', but that only works in IE, not
firefox 1.0.
am i using an IE-only javascript feature? the code from the javascript file
is below, and if you'd like to see it in action, go to
http://www.google.ie/search?num=100&...software+iserc and
click the first link (at time of writing it is www.iserc.ie/diary/2004/
november5isercworkshopadaptivesoftware/) . you need to go through google to
get the referrer. you should see the message at the top when the page
loads, and clicking the link should remove the highlighting and message.
i've done as much debugging as i can, and the RemoveHighlight function is
executing, and it does return the HighlightMsg div with the getElementByID
function correctly. it's just that RemoveNode does nothing to it for
firefox, but it works in IE.
thanks for any help
tim mackey. code below.
function Highlight(element)
{
...
//Replace search words
var msg = "<div id='HighlightMsg'>Your search terms have been highlighted:
";
var color = 0;
var max = 5;
for(j=0; j<aWords.length; j++)
{
regexp= new RegExp ("(" + aWords[j] + ")", "gi");
vStrippedHTML = vStrippedHTML.replace(regexp,'<span class="hl' + color+
'">$1</span>');
// build up message notifying user of highlighting
msg = msg + "<span class='hl" + color+ "'>" + aWords[j] + "</span> ";
color++;
}
//Reinsert HTML
for(i=0;vStrippedHTML.indexOf("$!$") > -1;i++)
vStrippedHTML = vStrippedHTML.replace("$!$", vHTMLArray[i]);
msg = msg + " - <a
href='javascript:RemoveHighlight(document.getEleme ntById(\"HTML\"))'>Remove
Highlighting</a></div>";
element.innerHTML = msg + vStrippedHTML;
}
function RemoveHighlight(element)
{
document.getElementById("HighlightMsg").removeNode (true);
regexp=/(<span class\=hl\d>)([^<>]*)(<\/span>)/ig;
element.innerHTML = element.innerHTML.replace(regexp, "$2");
}
window.onload=function(){Highlight(document.getEle mentById("HTML"));};
\\ email: tim at mackey dot ie //
\\ blog: http://tim.mackey.ie //
67d0ebfec70e8db3