How to highlight the searched words ?

Discussion in 'HTML' started by Roland, Dec 2, 2004.

  1. Roland

    Roland Guest

    Hello there
    I wrote one program in VC++ to highlight all words found in page
    currently navigated in browser. For that I am just appending
    "<span id=\"HTMLSEARCH\" STYLE=\"background-color: Highlight
    COLOR:HighlightText\"\\>" it to words found so as to highlight the
    words. My problem is that if the background color is same as
    highlighted color them you can't read the word. I want to highlight
    the word just like when you select any word using mouse. It highlights
    the word and sets the background color which is exact reverse to
    previous background color. How can I do this ?
    Should I chage the background-color and color ?
     
    Roland, Dec 2, 2004
    #1
    1. Advertising

  2. Roland

    SpaceGirl Guest

    Roland wrote:
    > Hello there
    > I wrote one program in VC++ to highlight all words found in page
    > currently navigated in browser. For that I am just appending
    > "<span id=\"HTMLSEARCH\" STYLE=\"background-color: Highlight
    > COLOR:HighlightText\"\\>" it to words found so as to highlight the
    > words. My problem is that if the background color is same as
    > highlighted color them you can't read the word. I want to highlight
    > the word just like when you select any word using mouse. It highlights
    > the word and sets the background color which is exact reverse to
    > previous background color. How can I do this ?
    > Should I chage the background-color and color ?


    In VBScript it's really easy;

    x = searchTerm

    pagetext= (page content fetched from a database or something)

    newpagetext = replace(pagetext,x,"<span class='highlighted'>" & x &
    "</span>"

    response.write newpagetext


    --


    x theSpaceGirl (miranda)

    # lead designer @ http://www.dhnewmedia.com #
    # remove NO SPAM to email, or use form on website #
     
    SpaceGirl, Dec 2, 2004
    #2
    1. Advertising

  3. Roland

    Steve Pugh Guest

    SpaceGirl <> wrote:
    > Roland wrote:
    >>I wrote one program in VC++ to highlight all words found in page
    >> currently navigated in browser. For that I am just appending
    >> "<span id=\"HTMLSEARCH\" STYLE=\"background-color: Highlight
    >> COLOR:HighlightText\"\\>" it to words found so as to highlight the
    >> words. My problem is that if the background color is same as
    >> highlighted color them you can't read the word. I want to highlight
    >> the word just like when you select any word using mouse. It highlights
    >> the word and sets the background color which is exact reverse to
    >> previous background color. How can I do this ?
    >> Should I chage the background-color and color ?


    You're missing the semi-colon between the two properties in your style.
    Is this just a typo in your post?

    You're using the system colours correctly
    <http://www.w3.org/TR/CSS21/ui.html#system-colors>
    but obviously the browsers (certainly IE6 and Opera 7.54) aren't smart
    enough to apply the same adjustment to those colours that they apply to
    real highlighting when the page background differs from the system
    background colour.

    So, you're probably better off defining your own hightlight colours and
    using them instead of the system colours.

    > In VBScript it's really easy;
    >
    > x = searchTerm
    >
    > pagetext= (page content fetched from a database or something)
    >
    > newpagetext = replace(pagetext,x,"<span class='highlighted'>" & x &
    > "</span>"
    >
    > response.write newpagetext


    Um, I don't think that answers the question at all.

    Or is class="highlighted" some predefined classname in VBScript that
    magically does what the OP needs with regards to the system colours?

    Steve
     
    Steve Pugh, Dec 2, 2004
    #3
  4. Roland

    SpaceGirl Guest

    Steve Pugh wrote:
    > SpaceGirl <> wrote:
    >
    >> Roland wrote:
    >>
    >>> I wrote one program in VC++ to highlight all words found in page
    >>> currently navigated in browser. For that I am just appending
    >>> "<span id=\"HTMLSEARCH\" STYLE=\"background-color: Highlight
    >>> COLOR:HighlightText\"\\>" it to words found so as to highlight the
    >>> words. My problem is that if the background color is same as
    >>> highlighted color them you can't read the word. I want to highlight
    >>> the word just like when you select any word using mouse. It highlights
    >>> the word and sets the background color which is exact reverse to
    >>> previous background color. How can I do this ?
    >>> Should I chage the background-color and color ?

    >
    >
    > You're missing the semi-colon between the two properties in your style.
    > Is this just a typo in your post?
    >
    > You're using the system colours correctly
    > <http://www.w3.org/TR/CSS21/ui.html#system-colors>
    > but obviously the browsers (certainly IE6 and Opera 7.54) aren't smart
    > enough to apply the same adjustment to those colours that they apply to
    > real highlighting when the page background differs from the system
    > background colour.
    >
    > So, you're probably better off defining your own hightlight colours and
    > using them instead of the system colours.
    >
    >> In VBScript it's really easy;
    >>
    >> x = searchTerm
    >>
    >> pagetext= (page content fetched from a database or something)
    >>
    >> newpagetext = replace(pagetext,x,"<span class='highlighted'>" & x &
    >> "</span>"
    >>
    >> response.write newpagetext

    >
    >
    > Um, I don't think that answers the question at all.
    >
    > Or is class="highlighted" some predefined classname in VBScript that
    > magically does what the OP needs with regards to the system colours?
    >
    > Steve
    >


    Yeah sorry... I misunderstood the question I think. Sorry!

    --


    x theSpaceGirl (miranda)

    # lead designer @ http://www.dhnewmedia.com #
    # remove NO SPAM to email, or use form on website #
     
    SpaceGirl, Dec 2, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. koffer
    Replies:
    0
    Views:
    478
    koffer
    Mar 23, 2005
  2. shapper

    Highlight Words

    shapper, Nov 27, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    408
    Mark Rae
    Nov 27, 2006
  3. Peng Yu
    Replies:
    6
    Views:
    1,397
  4. PiGei

    How to highlight words of a search

    PiGei, Mar 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    137
    Aaron [SQL Server MVP]
    Mar 16, 2005
  5. Peng Yu
    Replies:
    0
    Views:
    201
    Peng Yu
    Feb 20, 2010
Loading...

Share This Page