PDA

View Full Version : Highlighting the selected text script compatibile with Firefox



codeexploiter
02-08-2007, 05:56 AM
Hi

I am looking for a JavaScript based script which does the following functionality:

1. When I select a collection of character(s) that they should be highlighted I mean changing the background color of the selected text.

I've found a way around in IE but Firefox...........

Thanks in advance

jscheuer1
02-08-2007, 06:34 AM
Almost all browsers automatically change the background color when selecting characters. You must be talking about something else. How about a link to your page?

codeexploiter
02-08-2007, 06:40 AM
Hi John,

I am working on some inhouse project. I am trying to simulate a highlighter which will highlight the user selected text once they press a button after the text selection.

The objective is to make the selected text different from other text (highlighting).

I've done this in IE with the following code


theSelection = document.selection.createRange().htmlText;
document.selection.createRange().pasteHTML("<span style='background-color: yellow;'>" + theSelection + "</span>");


The above code is an IE specific one.

codeexploiter
02-08-2007, 07:44 AM
John I've figured it out and it is working in Firefox also.

shachi
02-08-2007, 08:19 AM
codeexploiter: Would you mind to post your code here? You don't have to if you don't want to but maybe someone(even me) might find it useful?

jscheuer1
02-08-2007, 10:18 AM
This reminded me of a thread on another forum. I'm not sure if these routines are still current or would work for this but, it is interesting stuff and is at least along the same lines:

http://www.ms-inc.net/ViewThread.aspx?ThreadID=169

jplanet
08-02-2007, 05:01 PM
John I've figured it out and it is working in Firefox also.

I have been struggling with this! If anyone knows how to get the selected text highlighted in Firefox, I would greatly appreciate it.

Codeexploiter, if you're still active on the forum and you see this, any help would be greatly appreciated!

xavierbabu
05-02-2008, 06:38 AM
Hi codeexploiter,

could you please share the code with us? We are struggling to get it done for Firefox

Thanks & Regards
A. Xavier

rangana
05-02-2008, 10:14 AM
John, your page is unavailable. Is that the correct one?

rangana
05-02-2008, 10:22 AM
Hi codeexploiter,

could you please share the code with us? We are struggling to get it done for Firefox

Thanks & Regards
A. Xavier

You might find this link useful (cross-browser)
http://www.nsftools.com/misc/SearchAndHighlight.htm