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";
}
}
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.
rakesh bairiPosted Sep 27, 2011, 1:52 AM
Actually i m developing a education website..Im displaying text in a Label.In that users will read a lesson if he want to highlight any points he can done through selecting text with mouse and he clicks on a buttonThen text has to highlighted it is ok if we can change forecolor of text.But when next time same user open same lesson he has to get highlighted text as it is.Its working fine in IE i m saving Entire page with html tags.Its working in Local When i m uploading it on server.Its getting an error that its not allowing me to assigning a text with html tags to a hidden field in javascript.
Plz suggest a solution. how i will get entire Label Text to server side.
Sam HobbsPosted Sep 23, 2011, 10:50 PM
For one thing, as I recall there are a couple of ways to turn on design mode and one way works in some browsers and the other way in other browsers, or something like that. I am not experienced with Firefox so I can't help with that. I think the first thing I would do is to determine if setting designMode is working. I think that you must set the designMode before doing the other things. Make sure that you are setting designMode or whatever it is called for Firefox in the correct way and at the correct time.
Also, are you sure that "execCommand" works the same for all browsers? I suspect not. So I would certainly investigate to determine if it is valid.
Are you sure that you need to change the background color? Would it be sufficient to just use the default behavior for selecting text? The default for this editor that I am using to type into is to make the background blue and the foreground (text) white. I suggest using that; at least for now, and then when you have everything else working, try improving it to change the background color.