Change URLs in search results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anbaxter
    New Member
    • Apr 2008
    • 1

    Change URLs in search results

    I have a small challenge and you'll have to excuse me because I haven’t touched JS for some time and have gotten a bit rusty.

    I have an intranet site at work that has roughly 500,000 htm pages (no joke). I have a search engine (zoom) that returns results of the various htm files. The site that I indexed is setup with about 41,600 folders with each folder containing 12 to 13 htm files. One of the htm files is a default.htm file that is actually a frame page that displays the other htm files. When I ran zoom to index the site it did not index the default.htm pages in each folder because there is no text in it.

    My users need to always see the default.htm page rather than being able to select the other pages from the search engine.

    So what I want to do is put a JavaScript on the search results page that looks at the various URLs and changes the URL OnClick to "default.ht m" if it finds one of the htm pages in the URL.

    The htm files to change are as follows:

    doc_index.htm
    document_histor y.htm
    frame_menu.htm
    project_history .htm
    status.htm
    status_history. htm
    summary.htm
    task_history.ht m
    task_list.htm
    terms.htm
    terms_history.h tm

    Is there a quick and easy way to do this?

    Thanks in advance for any help.
    Last edited by anbaxter; Apr 3 '08, 01:50 PM. Reason: typo
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    In your search page, you might be using <a> to link to each search result.
    In each <a> tag, add onclick="return goToDefault(thi s);"

    And the JS is...
    [code=javascript]function goToDefault(lin k) {
    arr = link.href.split ('/');
    arr[arr.length-1] = 'default.htm';
    link.href = arr.join('/');
    return true;
    }[/code]

    Or second option is, you can add a function on the onload event of body.
    [code=javascript]function changeHrefsToDe faultHtm() {
    var link = document.getEle mentsByTagName( 'a');
    for (var i=0; i<link.length; i++)
    //if (link[i].className=='se archLink')
    {
    arr = link[i].href.split('/');
    arr[arr.length-1] = 'default.htm';
    link[i].href = arr.join('/');
    }
    }[/code]But this will change all the links in your page, so its not recommended, unless you have something unique about the search result links.
    Eg. If the class name is unique, remove forward slashes from line 4


    Regards,
    Harpreet

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      The other option (if possible depending on how you have it set up) is to change each of those files to force them into the frame. Now if you're not using SSI (server side includes), this is not possible - well, it is, but it'd take forever to do.

      Comment

      Working...