By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,230 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,230 IT Pros & Developers. It's quick & easy.

Change URLs in search results

P: 1
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.htm" if it finds one of the htm pages in the URL.

The htm files to change are as follows:


Is there a quick and easy way to do this?

Thanks in advance for any help.
Apr 3 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,654
In your search page, you might be using <a> to link to each search result.
In each <a> tag, add onclick="return goToDefault(this);"

And the JS is...
Expand|Select|Wrap|Line Numbers
  1. function goToDefault(link) {
  2.     arr = link.href.split('/');
  3.     arr[arr.length-1] = 'default.htm';
  4.     link.href = arr.join('/');
  5.     return true;
  6. }
Or second option is, you can add a function on the onload event of body.
Expand|Select|Wrap|Line Numbers
  1. function changeHrefsToDefaultHtm() {
  2.     var link = document.getElementsByTagName('a');
  3.     for (var i=0; i<link.length; i++)
  4.     //if (link[i].className=='searchLink')
  5.     {
  6.         arr = link[i].href.split('/');
  7.         arr[arr.length-1] = 'default.htm';
  8.         link[i].href = arr.join('/');
  9.     }
  10. }
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

Apr 3 '08 #2

Expert Mod 15k+
P: 16,027
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.
Apr 4 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.