Results 1 to 10 of 10

Thread: Highlighting the selected text script compatibile with Firefox

  1. #1
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default Highlighting the selected text script compatibile with Firefox

    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    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
    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.

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    John I've figured it out and it is working in Firefox also.

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    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!

  8. #8
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi codeexploiter,

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

    Thanks & Regards
    A. Xavier

  9. #9
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    John, your page is unavailable. Is that the correct one?
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  10. #10
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Quote Originally Posted by xavierbabu View Post
    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
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •