Hvis det er en søgemaskine du skal have på dit eget site, og at du kun vil søge på nogle sider, ja så er det en lidt stører ting du er igang med:)
Men her er en søgefunktion i JavaScript, hvor man selv fortæller hvilke sider den skal søge i. Dette eksempel er lavet i en frame løsning!
FRAME SRC ser således ud:
<HTML>
<HEAD>
<TITLE>JavaScript Site Search</TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var test="a";
/* Here is where all the magic happens.
Put the file name then ~ with a space,
then the page title, then || then the
keywords separated by spaces and a star
at the end. Repeat for additional pages. */
var find='
http://www.?.dk/page1.htm~ The JavaScript Source Main Page||java script help demo main*'
+'
http://www.?.dk/page2.htm~ The JavaScript Source Feedback||feedback question answer comments*'
// End -->
</SCRIPT>
<FRAMESET ROWS="50%,50%">
<FRAME SRC="site-search-main.html" SCROLLING="yes" NAME="main">
<FRAME SRC="site-search-display.html" SCROLLING="no" NAME="results">
</FRAMESET>
</HTML>
-------------------------
Og så til selve søgesiden:
-------------------------
<HTML><HEAD>
<TITLE>Untitled</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function doSrch(){
parent.test="b";
parent.results.location.href="site-search-display.html"
}
// End -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function doSrch(){
parent.test="b";
parent.results.location.href="site-search-display.html"
}
// End -->
</SCRIPT>
<BODY>
<CENTER>
<FORM NAME="searcher" onSubmit="doSrch();return false">
<TABLE BORDER=0 WIDTH=486>
<TR>
<TD ALIGN=CENTER><B>Search Our Site For Topic Words</B>
<P>Type Search Word Here: <INPUT TYPE="text" NAME="findword" VALUE="" SIZE=20>
<INPUT TYPE="button" NAME="button" VALUE=" Search " onClick="doSrch();"></TD>
</TR>
</TABLE>
</FORM>
</CENTER>
</BODY>
</HTML>
------------------------------
og til sidst den side som søgeresultatet skal vises i, der er en del kode på denne side, men det er standart kode, så der skulle ikke være nødvendigt at ændre i den, udover formatering af "visning af resultat"
------------------------------
<HTML><HEAD>
<TITLE>Untitled</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function initArray(){
this.length=initArray.arguments.length;
for (var i=0;i<this.length;i++){
this[i]=initArray.arguments[i];
}
}
var sr=new initArray("4b","5b","8b","8b");
function doSrch(){
if (sr[0]=="4b"){
parStr();
}
findw = parent.main.document.searcher.findword.value
findw=findw.toLowerCase();
disp = "";
document.write('<HTML><BODY BGCOLOR="white">'
+'<CENTER><FORM NAME="isn"><TABLE BORDER=0 '
+'WIDTH=486><TR><TD VALIGN=TOP></TD><TD><SE'
+'LECT NAME="isn1" SIZE=6>');
flg=2; // Set flag to "no matches found"
for (i=0;i<stp;i++){
fold=sr[i].toLowerCase();
if (fold.indexOf(findw)>-1){
pos=sr[i].indexOf("~");
pos1=sr[i].indexOf("||");
disp="<OPTION VALUE='"+sr[i].substring(0,pos);
if (flg!=3){
// disp+='<TD><SELECT NAME="isn1" SIZE=6>'+disp;
disp+="' onClick='' SELECTED>";
}
else{
disp+="' onClick=''>";
}
disp+=sr[i].substring(pos+1,pos1);
document.write(disp);
flg=3; // Set flag to "matches found"
}
}
if (flg!=2){
document.write('</SELECT></TD><TD VALIGN=TOP'
+'><INPUT TYPE="button" NAME="button" Value'
+'=" Select and Go " onClick="doloc(this.fo'
+'rm)"><BR>');
}
document.write('<BR><FONT COLOR="red"><B>');
if (flg!=3){
document.write('</TD><TD VALIGN=CENTER><FONT '
+'COLOR="red"><B><BR>I\'m sorry. I found no matches'
+' for "'+findw+'".<P>Feel free to perform'
+' another search!</B></FONT>');
}
else{
document.write('The selection(s) at left w'
+'ere<BR>found using keyword "'+findw+'".');
}
document.write('</B></FONT></TD></TR></TABLE>'
+'</FORM></BODY></HTML><P>');
}
function parStr() {
srs=parent.find;
var i=0;
while (srs.indexOf("*")>0) {
pos=srs.indexOf("*");
sr[i]=srs.substring(0,pos);
srs=srs.substring(pos+1,srs.length);
i++;
stp=i;
}
}
function doloc() {
durl=(document.isn.isn1.options[document.isn.isn1.selectedIndex].value);
/* This next line will target the selection
to the main pane of your frameset. */
parent.main.location.href=durl;
/* But if you wish to target the selection to the top
(just as you would use <A HREF="filenm" TARGET="_top">)
simply uncomment this next line and use it instead:
parent.location.href=durl;
and comment out the line now being used above. */
}
// End -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR=white>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (parent.test != "a") {
doSrch();
}
// End -->
</SCRIPT>
</BODY>
</HTML>
/KAN