Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Thanked 0 Times in 0 Posts

    Intuitive approach

    Hi guys,
    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')[0];
    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);

  2. #2
    Regular Coder
    Join Date
    Feb 2009
    Wheeling, IL
    Thanked 62 Times in 60 Posts
    Why cross-post? And in the same forum at that... seriously, try and read the rules regarding posting here.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?


Posting Permissions

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