網頁文字搜尋引擎

Home Home
引用 | 編輯 ericleesky
2005-03-15 18:12
樓主
推文 x0
‧步驟一:將以下原始碼加入<HEAD>與</HEAD>標籤之間.

<!--
var NS4 = (document.layers);
var IE4 = (document.all);
var win = this;
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 );
}
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 )
}}
return false;
}
// -->
</script>


‧步驟二:將以下原始碼加入網頁中欲出現搜尋引擎之位置即可.

<form name=search>
<font color="#CC0000">請輸入你想尋找的關鍵字,僅限本網頁</font><BR>
<input name=string type=text size=15 onfiltered="n = 0;">
<input type=button value="搜尋" onfiltered="findInPage(this.form.string.value);"></form>

獻花 x0