#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    1
    Rep Power
    0

    Highlight search keywords on HTML page


    I have an ASP search function which, after typing the search term, searches HTML pages and creates a list of links.

    The problem is that I do not know how to code so the search term is highlighted in red after the user clicks on the link to view the HTML page.

    Any ideas?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    NJ, USA
    Posts
    11
    Rep Power
    0
    Hi,

    I have to speculate on how you will be searching HTML pages.

    My best guess form your message is that you will be opening and reading the text of html files within your site, and looking for user supplied search words.

    Assuming this is your plan, you will need to write a temporary version of your searched files out where the html of the searched pages is modified to contain extra tags around the user requested search terms.

    Add to this that other people will be doing other searches at the same time and you will need to create multiple sets of "searched HTML pages", and not to mention that you will then have to delete the pages after the user is done, and you have a bit of a nightmare on your hands.

    This capability is made easier by the build-in Search mechanism, and some ASP-like programming, but be advised, that this search mechanism is the a favorite hackers playground.

    Another alternative is to read the text of your html messages and make a new, super page containing the actual text of the searched pages, but this depends on how far from your original vision you can stray.

    Another way is to modify the HTML and temporarily store it into a database and the links would not actually be to an HTML file, but to the edited (link added) version of the HTML file stored in a database record.


    Then again, I may have of mis-understood from the beginning, and your search is actually something else.

    Ray Hogan
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Minneapolis, MN
    Posts
    11
    Rep Power
    0
    What I have done is the past is uses css and some text logic. I just put this togther as an example, but I think it is about 95% of what you need.

    Hope this helps

    JM

    Place this in the <head> of your results page
    ----------------------------------------------------------------------------

    .higlight
    {
    background: 000099; // or whatever color you want to use
    }

    Place this code somewhere after you retrieve you recordset
    ----------------------------------------------------------------------------
    'get your searched text and the keyword(s)
    sMySearchedText = objRS("FAQAnswer")
    sMyKeyWord = Request.Form("Keyword")

    ' you can tokenize this is you have to with
    sKeyword() = split(sMyKeyWord, " ")

    i = 1
    Do

    ' check to see if the keyword in is the searched text, if so return the position (iIndex)
    iIndex = Instr(1,sMySearchedText, sKeyword(i))
    If iIndex > 0 then

    iLength = Len(sKeyword(i))
    ' set sLeftTemp equal to all text up to the keyword
    sLeftTemp = Left(sMySearchedText, iIndex - 1)

    ' set sRightTemp equal to all text past the keyword
    sRightTemp = Mid(iIndex+ iLength + 1,sMySearchedText)

    ' change to keyword to be highlighted
    sTemp = "<span class=""highlight"">" & sKeyword(i) & "</span>"

    'Put it all back together
    sMySearchedText = sLeftTemp & sTemp & sRightTemp

    End If

    i = i + 1
    Loop

IMN logo majestic logo threadwatch logo seochat tools logo