专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Asp教程 » google站内搜索代码:站内搜索代码 »正文

google站内搜索代码:站内搜索代码

来源: 发布时间:星期四, 2009年2月12日 浏览:612次 评论:0


很多人在找站内搜索代码可是找个真正好用我也是找了很久才找到了找个站内搜索代码呵呵拿出来和大家起分享以后不记得就可以直接来这里看看了

脚本介绍说明:
步:把如下代码加入<body>区域中
<script language=\"JavaScript\">
<!--
// 下面是负责搜索页面全路径或相对路径
var search_htm_url = \"searchsource.htm\";
function searchPage {
((document.searchpage.keyword.value.length 0)
|| (document.searchpage.keyword.value \" \")) {
alert(\"请填入关键字!\");
} {
sel = document.searchpage.and_or.selectedIndex;
location.href = search_htm_url + \"?\"
+ escape(document.searchpage.keyword.value)
+ (sel0?\"&and\":(sel2?\"&exact\":\"&or\"));
}
false;
}
document.write(\'<form name=\"searchpage\" >\'
+\'请填入关键字: <input type=\"text\" size=22 name=\"keyword\"> \'
+\'<input type=\"button\" value=\"Search\" ><br>\'
+\'<select name=\"and_or\" size=1><option>关键字和搜索<option>关键字或搜索 \'
+\'<option>关键字异或搜索</select></form>\');
// -->
</script>
第 2步:新建searchsource.htm 其内容为
<!-- 代码开始-->
<form NAME=\"database\">
<input type=\"hidden\" name=\"list\"
value=\"http://www.njcatv.net~南京有线电视台网站WebSite|njcatv 南京有线电视台 网页特效 影音空间 新闻 javascript java applet 健康的桥^为广大南京市民提供全方位信息和帮助*http://www.sina.com.cn~最全中文新闻发部站点|sina 新浪 新闻 super 王志东 聊天室^国内最大新闻网站WebSite!*http://www.163.net~最大综合中文网站WebSite|163 netease 网易 丁磊 新闻 yeah 126 娱乐 freemail 聊天室^最大综合中文网站WebSite,为你提供全方位各种信息是你上网好去处!*http://www.sohu.com~最大中文引擎搜索站点|sohu search 搜索 引擎 张朝阳 聊天室^最大中文引擎搜索站点是你上网查找资料最好去处!*http://www.sohu.com~最大中文引擎搜索站点|sohu search 搜索 引擎 张朝阳 聊天室^最大中文引擎搜索站点是你上网查找资料最好去处!*http://www.sohu.com~最大中文引擎搜索站点|sohu search 搜索 引擎 张朝阳 聊天室^最大中文引擎搜索站点是你上网查找资料最好去处!*http://www.sohu.com~最大中文引擎搜索站点|sohu search 搜索 引擎 张朝阳 聊天室^最大中文引擎搜索站点是你上网查找资料最好去处!*http://www.sohu.com~最大中文引擎搜索站点|sohu search 搜索 引擎 张朝阳 聊天室^最大中文引擎搜索站点是你上网查找资料最好去处!*http://www.sohu.com~最大中文引擎搜索站点|sohu search 搜索 引擎 张朝阳 聊天室^最大中文引擎搜索站点是你上网查找资料最好去处!\">
</form>
<!-- 以下代码不要变动-->
<script language=\"JavaScript\">
<!--
function Page(url,title,keywords,description) { [Page]
while ((url.length > 0) && (url.charAt(0) \" \")) {
url = url.sub(1,url.length);
}
this.url = url;
while ((title.length > 0) && (title.charAt(0) \" \")) {
title = title.sub(1,title.length);
}
this.title = title;
this.keywords = keywords;
this.description = description;
this;
}
function Database {
var pos = 0;
while ((pos1 = amorphous.indexOf(\"~\",pos)) != -1) {
pos2 = amorphous.indexOf(\"|\",pos1+1);
pos3 = amorphous.indexOf(\"^\",pos2+1);
pos4 = amorphous.indexOf(\"*\",pos3+1);
((pos2 != -1)
&& (pos2 < pos3) && (pos3 < pos4)
&& (pos4 <= amorphous.indexOf(\"*\",pos))) {
this[database_length] = Page(amorphous.sub(pos,pos1),
amorphous.sub(pos1+1,pos2),
amorphous.sub(pos2+1,pos3),
amorphous.sub(pos3+1,pos4));
pos = pos4+1;
} { // error reading amorphous database
(pos+30 <= amorphous.length)
alert(\'Error reading in amorphous database around \"\'
+ amorphous.sub(pos,pos+30) + \'\"\');
pos = amorphous.indexOf(\"*\",pos) + 1;
}
}
this;
}
function search(str) {
menu_length = 0;
temp = Object;
temp_length = 0;
words_length = 0;
words = Object;
pos = 0;
while ((pos = str.indexOf(\" \")) != -1
&& and_search != \"exact\") {
words[words_length] = str.sub(0,pos);
(words[words_length].length > 0)
words_length;
(str.length 1)
str=\"\";

str = str.sub(pos+1,str.length);
}
(str.length > 0)
words[words_length] = str;
for (q=0;q<words_length;q) {
temp_length = 0;
str = words[q].toLowerCase;
len = (and_search\"and\"&&q>0?menu_length:database_length);
for (n=0; n<len; n) {
(and_search\"and\"&&q>0) {
combo = (menu[n].title + \" \" + menu[n].description
+ \" \" + menu[n].keywords).toLowerCase;
} {
combo = (database[n].title + \" \" + database[n].description
+ \" \" + database[n].keywords).toLowerCase;
}
(combo.indexOf(str) != -1) // found
temp[temp_length] = (and_search\"and\"&&q>0?menu[n]:database[n]);
}
(and_search!=\"and\" && q>0) {


added = 0;
for (i=0;i<temp_length;i) {
duplicate = false;
for (j=0;j<menu_length&&!duplicate;j) {
(menu[j] temp[i]) {
duplicate = true;
}
}
(!duplicate)
menu[menu_length+(added)] = temp[i];
}
menu_length added;
} {
for(h=0;h<temp_length;h)
menu[h] = temp[h];
menu_length = temp_length;
}
}
}
function entry {
((document.entryform.keyword.value.length 0)
|| (document.entryform.keyword.value \" \")) { [Page]
alert(\"你必须填写关键字!\");
false;
}
and_search = (document.entryform.and_or.selectedIndex 0?\"and\":\"or\");
(document.entryform.and_or.selectedIndex 2)
and_search = \"exact\";
location.href = location.pathname + \"?\"
+ escape(document.entryform.keyword.value)
+ (and_search != \"or\"?\"&\"+and_search:\"\");
false;
}
function redWord(str) {
for(r=0; r<words_length; r) {
pos = -3;
word = words[r].toLowerCase;
while ((pos = str.toLowerCase.indexOf(word,pos+3)) != -1) {
val = pos+word.length;
str = str.sub(0,pos) + \"*\"
+ str.sub(pos,val) + \"|\"
+ str.sub(val,str.length);
}
}
pos = -16;
while ((pos = str.toLowerCase.indexOf(\"*\",pos+16)) != -1)
str = str.sub(0,pos) + \"<font color=red>\"
+ str.sub(pos+1,str.length);
pos = -7;
while ((pos = str.toLowerCase.indexOf(\"|\",pos+7)) != -1)
str = str.sub(0,pos) + \"</font>\"
+ str.sub(pos+1,str.length);
str;
}
var amorphous = document.database.list.value;
temp_str = amorphous.sub(amorphous.length-2,amorphous.length);
(temp_str.indexOf(\"*\") -1)
amorphous \"* \";

amorphous \" \"; // amorphous database must have characters after last asterisk
database_length = 0; // Netscape 2 fix
var database = Database; // read in from amorphous database
menu_length = 0; // Netscape 2 fix
var menu = Object;
= \"\";
and_search = \"or\";
(location.search.length > 1) {
= unescape(location.search.sub(1,location.search.length));
pos = 0;
while ((pos = .indexOf(\'\"\',pos)) != -1) {
= .sub(0,pos) + \'\\\"\' + .sub(pos+1,.length);
pos 2;
}
(.sub(.length-4,.length) \"&and\") {
= .sub(0,.length-4);
and_search = \"and\";
} (.sub(.length-6,.length) \"&exact\") {
= .sub(0,.length-6);
and_search = \"exact\";
} (.sub(.length-3,.length) \"&or\") {
= .sub(0,.length-3);
and_search = \"or\";
}
search();
}
document.write(\'<form name=\"entryform\" >\'
+\'Search for:<input type=\"text\" size=22 \'
+\'name=\"keyword\" value=\"\'++\'\"> \'
+\'<input type=\"button\" value=\"Search\" ><br><select name=\"and_or\" \'
+\'size=1><option\'+(and_search\"and\"?\" selected\":\"\")+\'>Search All word \'
+\'(AND)<option\'+(and_search\"or\"?\" selected\":\"\")+\'>Search any word \'
+\'(OR)<option\'+(and_search\"exact\"?\" selected\":\"\")+\'>Exact \' [Page]
+\'word</select></form><br>\');
(location.search.length > 1)
document.write(\'查询结果:<br><br>n\');
for (n=0; n<menu_length; n)
document.write(\'<a href=\"\'+menu[n].url+\'\">\'+menu[n].title
+\'</a><br>\'+redWord(menu[n].description)+\'<br>Keywords: \'
+redWord(menu[n].keywords)+\'<br><br>n\');
((menu_length 0) && (location.search.length > 1))
document.write(\'对不起:你查询关键字\"\'++\'\"没有发现!n\');
// -->
</script>


1

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: