Javascript搜索引擎(搜索自己的网站)

编程入门 行业动态 更新时间:2024-10-09 18:23:29
本文介绍了Javascript搜索引擎(搜索自己的网站)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想要一个只搜索我自己的网站的搜索引擎。我目前有一些JavaScript,但它只在特定页面上搜索单词。如果可能的话,我需要它搜索我网站中的链接。

我的网站位于内部Intranet上,因此无法使用Google搜索引擎。

< SCRIPT language = JavaScript> var NS4 =(document.layers); var IE4 =(document.all); var win = window; var n = 0; 函数findInPage(str){ var txt,i,found; if(str ==) return false; 如果(NS4){ if(!win.find(str)) while(win.find(str,false,true)) n ++; else n ++; if(n == 0) alert(Not found。); } 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(对不起,我们找不到了。再试一次); } } 返回false; } < / SCRIPT>

(onsubmit =return findInPage(this.string.value); )

它可以很好地搜索那个页面,但我希望有一种方法可以搜索所有页面我的网站。

解决方案

几点建议:

  • 除非必须,否则不要重新发明轮子 - 有开源库,如Tipue Search( Tipue Search )和其他。
  • 您可以使用jquery / ajax $ .load()来动态加载页面内容并搜索它们,同时仍然保留在相同的页面中,直到您的DOM和脚本
  • NodeJS也是一个不错的选择,但可能会被杀死。
  • 希望这有助于!

    I want to have a search engine which searches only my own site. I have some JavaScript currently, but it only searches words on that specific page. I need it to search the links within my site if possible.

    I cannot use the Google search engine as my site is on an internal intranet.

    <SCRIPT language=JavaScript> var NS4 = (document.layers); var IE4 = (document.all); var win = window; 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("Not found."); } 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("Sorry, we couldn't find.Try again"); } } return false; } </SCRIPT>

    (onsubmit="return findInPage(this.string.value); in the button tag.)

    It works great for searching that page, but I was hoping there was a way to search all pages on my site.

    解决方案

    Few suggestions:

  • Unless you must, don't re-invent the wheel - there are open source libraries such as Tipue Search (Tipue Search) and others.
  • You can use jquery/ajax $.load() to dynamically load page content and search them, while still staying in the same page as far as your DOM and script goes.
  • NodeJS is also a good option, but will probably be an over kill.
  • Hope this helps!

    更多推荐

    Javascript搜索引擎(搜索自己的网站)

    本文发布于:2023-11-01 00:49:30,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:自己的   搜索引擎   网站   Javascript

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!