rakesh bairi

rakesh bairi

  • 1.4k
  • 307
  • 3.2k

Highlight Selected Text

Sep 22 2011 9:17 AM
I am interested in saving text when user selects any text anywhere on a web page that text has to be highlighted and has to save that text as a string in DataBase.
when same user saw same page next time text has to be highlighted as done previously by him.
If anyone knows a simple elegant way to do this I would really appreciate it, but I'll take any solution at this point. Even if you can point me in the right directions that would be appreciated. Thanks in advance.

I m tried with this code


function highlight() {
var range, sel;
// IE case
if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
//range.execCommand("Bold", false, null);
range.execCommand("BackColor", "false", "yellow");
txt = document.selection.createRange().text;
} else if (window.getSelection) {
// Non-IE
sel = window.getSelection();
if (sel.rangeCount && sel.getRangeAt) {
range = sel.getRangeAt(0);
alert(range);
}
document.designMode = "on";
if (range) {
sel.removeAllRanges();
sel.addRange(range);
alert(range);
}
// document.execCommand("Bold", false, null);
document.execCommand("BackColor", "false", "yellow");
document.designMode = "ofx f";
}
}
</script>
but using this code i m getting problem in firefox but it works fine in IE,Chrome and also i have show highlight the text when same user open same page next time For that i have to store text in my database.