View Full Version : Intuitive approach

04-10-2009, 07:19 PM
Hi guys,
At present I am working on an annotaion tool for my thesis. Basically the user is able to select any text on a web page and change its text color background. the text and text color background are stored in a database so when the user re-vists the same page, the highlights re-appear. I am stuck with these 2 issues:

1) My highlight function highlights the 1st instance of the text selected.
2) When the page re-loads, it searches the page and highlight the first instance of the text. So if I highlight "the", on re-load it will find the first "the" and not necessarily the word or phrase I selected at the particualr postition.

Can anyone please help?

this is my code

var workArea = "";
workArea = content.document.getElementsByTagName('body')[0];
var openTag = '<span style="background-color: 'red'\'">';
var closeTag = '</span>';
workText = content.getSelection().getRangeAt(0);
var currReplace = new RegExp("("+workText+")");
workArea.innerHTML = workArea.innerHTML.replace(currReplace, openTag+"$1"+closeTag);

04-10-2009, 07:32 PM
Why cross-post? And in the same forum at that... seriously, try and read the rules regarding posting here.