PDA

View Full Version : Js internal search engine


Alex Piotto
05-14-2003, 05:24 PM
Hi people
I am trying to make an internal javascript search engine to search into an html page that contains links to different other pages in the same website.
I looked around on the net, but the only script that seems to make the job (almost, in this case) is the "FindInPage" script from "The JavaScript Source" website (below)

------------------------------------------------------

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var NS4 = (document.layers);
var IE4 = (document.all);

var win = top.documentos.main;
var n = 0;

function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0) alert(str + " was not found on this page.");
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + " não existe nesta lista.");
}
}
return false;
}
// End -->
</script>

----------------------------------------------------

Now, I need to adapt the script... hopefully with you help :)

(by the way, the search engine is in a frame structure... the html page that contains the links is in another frame... but this is not a problem).

Here we go....

The list of links is quite long, so when the scrollintoview function operates, it puts the highlighted word at the bottom of the page... so users have to scroll the page anyway to see the entire link title. It is not user friendly like that.... :(

Beside that, I would like to highlight the entire link title, and not only the word inside the link found during the search... and I would like to have the highlighted link at the top of the page.

The script as it is works fine, but I cant find a way to modify it without screwing it :(

Any help will be really appreciated

Thanks

Alex

primezero
05-14-2003, 09:38 PM
is this an offline JS search engine? like for a CD-ROM?

Alex Piotto
05-14-2003, 10:25 PM
No, it is not. Is online, on a website...