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');
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);