基本思路 利用表单将用户提交的搜索关键字存储在变量中,并提交给ASP脚本处理。利用ASP内建的“REQUEST”对象获取变量中的关键字符,随后用“RESPONSE”的“REDIRECT”函数将关键字符转向提交到其他的诸如搜狐、网易等专业搜索引擎中,即可得出搜索结果。使得访客在自己的主页上就可方便地使用各大搜索引擎,无需登录其主页面。
第一步 创建搜索引擎的主页面。在HTML文件
的< body>和< /body>之间加入代码如下:
< form name="form1" method="post" action="search.asp">
< div align="center">请选择您喜欢的搜索引擎< br>< br>
< select name="select" size="1">
< option>搜狐< /option>
< option>新浪(北京站)< /option>
< option>网易< /option>
< /select>< br>< br>
请键入您要查询的关键字< br>
< input type="text" name="textfield">
< br>< br>
< input type="submit" name="Submit" style="color:#CC0033background-color:#fffffffont-size:9ptborder:#CC0033 1px solidheight:18px"value="搜 索">
< /form>
在此,我们提供了搜狐、新浪、网易3种搜索引擎供用户选择,用户键入关键字串后,表单将请求提交到后台的 search.asp 处理。
第二步 编写后台的ASP程序。在HTML文件的< body>和< /body>之间加入下列代码:
< % if request.form("select")="搜狐" then response.redirect("
sitesearch.jsp?key_word="&&request.form("textfield")) end if
if request.form("select")="新浪(北京站)" then response.redirect("
sitesearch.jsp?key_word="&&request.form("textfield")) end if
if request.form("select")="网易" then response.redirect(""&&request.form("textfield")) end if
%>
在实现提交搜索字串到其他搜索引擎时,很关键的一点就是要明白这些搜索引擎所使用的查询格式。如搜狐用的就是“”搜索字串 。我们只需平时在使用这些搜索引擎时注意一下,给出搜索结果时把IE地址栏中的地址记录下来分析,去掉后面的诸如“%C1%F5%……”字符(这是我们提交的搜索字串转换成的字符),即可得到查询格式。
另外,很多搜索引擎使用了分类查找。可细分为“网站”、“网页”、“新闻”等类别,每一种类的查询格式均不相同,读者可以使用更多的IF语句建立选择项,实现同一搜索引擎内搜索种类的细分。
同理,我们还可把这个程序进行扩充,把其他的搜索引擎加入,使其功能更为强大。
分类: 电脑/网络 >>程序设计 >>其他编程语言问题描述:
类似于按F3的功能~!
只搜索当前页中是文字~!
不要查询数据库
解析:
<>
<head>
<meta -equiv="Content-Language" content="zh-">
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>test</title>
</head>
<body class="page_speeder_724936674">
<script language="JavaScript">
var NS4 = (documentyers)Which browser?
var IE4 = (document.all)
var win = windowwindow to search.
var n = 0
function findInPage(str) {
var txt, i, found
if (str == "")
return false
Find next occurance of the given string on the page, wrap around to the
start of the page if necessary.
if (NS4) {
Look for match starting at the current point. If not found, rewind
back to the first match.
if (!win.find(str))
while(win.find(str, false, true))
n++
else
n++
If not found in either direction, give message.
if (n == 0)
alert("本页没有查到.")
}
if (IE4) {
txt = win.document.body.createTextRange()
Find the nth match from the top of the page.
for (i = 0i <= n &&(found = txt.findText(str)) != falsei++) {
txt.moveStart("character", 1)
txt.moveEnd("textedit")
}
If found, mark it and scroll it into view.
if (found) {
txt.moveStart("character", -1)
txt.findText(str)
txt.select()
txt.scrollIntoView()
n++
}
Otherwise, start over at the top of the page and find first match.
else {
if (n >0) {
n = 0
findInPage(str)
}
Not found anywhere, give message.
else
alert("本页没有查到此题目,请尝试用下百度的搜索引擎在网上查下.")
}
}
return false
}
</script>
<div id="floater" class="page_speeder_1555397322">
<div align=center class="page_speeder_1173002127">
<script language=JavaScript>
self.onError=null
currentX = currentY = 0
whichIt = null
lastScrollX = 0lastScrollY = 0
NS = (documentyers) ? 1 : 0
IE = (document.all) ? 1: 0
<!-- STALKER CODE -->
function heartBeat() {
if(IE) { diffY = document.body.scrollTopdiffX = document.body.scrollLeft}
if(NS) { diffY = self.pageYOffsetdiffX = self.pageXOffset}
if(diffY != lastScrollY) {
percent = .1 * (diffY - lastScrollY)
if(percent >0) percent = Math.ceil(percent)
else percent = Math.floor(percent)
if(IE) document.all.floater.style.pixelTop += percent
if(NS) document.floater.top += percent
lastScrollY = lastScrollY + percent
}
if(diffX != lastScrollX) {
percent = .1 * (diffX - lastScrollX)
if(percent >0) percent = Math.ceil(percent)
else percent = Math.floor(percent)
if(IE) document.all.floater.style.pixelLeft += percent
if(NS) document.floater.left += percent
lastScrollX = lastScrollX + percent
}
}
<!-- /STALKER CODE -->
<!-- DRAG DROP CODE -->
function checkFocus(x,y) {
stalkerx = document.floater.pageX
stalkery = document.floater.pageY
stalkerwidth = document.floater.clip.width
stalkerheight = document.floater.clip.height
if( (x >stalkerx &&x <(stalkerx+stalkerwidth)) &&(y >stalkery &&y <(stalkery+stalkerheight))) return true
else return false
}
function grabIt(e) {
if(IE) {
whichIt = event.srcElement
while (whichIt.id.indexOf("floater") == -1) {
whichIt = whichIt.parentElement
if (whichIt == null) { return true}
}
whichIt.style.pixelLeft = whichIt.offsetLeft
whichIt.style.pixelTop = whichIt.offsetTop
currentX = (event.clientX + document.body.scrollLeft)
currentY = (event.clientY + document.body.scrollTop)
} else {
window.captureEvents(Event.MOUSEMOVE)
if(checkFocus (e.pageX,e.pageY)) {
whichIt = document.floater
StalkerTouchedX = e.pageX-document.floater.pageX
StalkerTouchedY = e.pageY-document.floater.pageY
}
}
return true
}
function moveIt(e) {
if (whichIt == null) { return false}
if(IE) {
newX = (event.clientX + document.body.scrollLeft)
newY = (event.clientY + document.body.scrollTop)
distanceX = (newX - currentX)distanceY = (newY - currentY)
currentX = newXcurrentY = newY
whichIt.style.pixelLeft += distanceX
whichIt.style.pixelTop += distanceY
if(whichIt.style.pixelTop <document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop
if(whichIt.style.pixelLeft <document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft
if(whichIt.style.pixelLeft >document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20
if(whichIt.style.pixelTop >document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5
event.returnValue = false
} else {
whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY)
if(whichIt.left <0+self.pageXOffset) whichIt.left = 0+self.pageXOffset
if(whichIt.top <0+self.pageYOffset) whichIt.top = 0+self.pageYOffset
if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17
if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17
return false
}
return false
}
function dropIt() {
whichIt = null
if(NS) window.releaseEvents (Event.MOUSEMOVE)
return true
}
<!-- DRAG DROP CODE -->
if(NS) {
window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN)
window.onmousedown = grabIt
window.onmousemove = moveIt
window.onmouseup = dropIt
}
if(IE) {
document.onmousedown = grabIt
document.onmousemove = moveIt
document.onmouseup = dropIt
}
if(NS || IE) action = window.setInterval("heartBeat()",1)
</script>
<form name=search onSubmit="return findInPage(this.string.value)">
<font size=3><font color="#FF0000"><br>
请输入关键字:<br>
</font><br>
<input name=string type=text size=10 onChange="n = 0"><br>
</font><br>
<input type=submit value="查找">
<input type=submit value="继续查"><br>
</form>
</div>
</div>
<script language=JavaScript>
self.onError=null
currentX = currentY = 0
whichIt = null
lastScrollX = 0lastScrollY = 0
NS = (documentyers) ? 1 : 0
IE = (document.all) ? 1: 0
<!-- STALKER CODE -->
function heartBeat() {
if(IE) { diffY = document.body.scrollTopdiffX = document.body.scrollLeft}
if(NS) { diffY = self.pageYOffsetdiffX = self.pageXOffset}
if(diffY != lastScrollY) {
percent = .1 * (diffY - lastScrollY)
if(percent >0) percent = Math.ceil(percent)
else percent = Math.floor(percent)
if(IE) document.all.floater.style.pixelTop += percent
if(NS) document.floater.top += percent
lastScrollY = lastScrollY + percent
}
if(diffX != lastScrollX) {
percent = .1 * (diffX - lastScrollX)
if(percent >0) percent = Math.ceil(percent)
else percent = Math.floor(percent)
if(IE) document.all.floater.style.pixelLeft += percent
if(NS) document.floater.left += percent
lastScrollX = lastScrollX + percent
}
}
<!-- /STALKER CODE -->
<!-- DRAG DROP CODE -->
function checkFocus(x,y) {
stalkerx = document.floater.pageX
stalkery = document.floater.pageY
stalkerwidth = document.floater.clip.width
stalkerheight = document.floater.clip.height
if( (x >stalkerx &&x <(stalkerx+stalkerwidth)) &&(y >stalkery &&y <(stalkery+stalkerheight))) return true
else return false
}
function grabIt(e) {
if(IE) {
whichIt = event.srcElement
while (whichIt.id.indexOf("floater") == -1) {
whichIt = whichIt.parentElement
if (whichIt == null) { return true}
}
whichIt.style.pixelLeft = whichIt.offsetLeft
whichIt.style.pixelTop = whichIt.offsetTop
currentX = (event.clientX + document.body.scrollLeft)
currentY = (event.clientY + document.body.scrollTop)
} else {
window.captureEvents(Event.MOUSEMOVE)
if(checkFocus (e.pageX,e.pageY)) {
whichIt = document.floater
StalkerTouchedX = e.pageX-document.floater.pageX
StalkerTouchedY = e.pageY-document.floater.pageY
}
}
return true
}
function moveIt(e) {
if (whichIt == null) { return false}
if(IE) {
newX = (event.clientX + document.body.scrollLeft)
newY = (event.clientY + document.body.scrollTop)
distanceX = (newX - currentX)distanceY = (newY - currentY)
currentX = newXcurrentY = newY
whichIt.style.pixelLeft += distanceX
whichIt.style.pixelTop += distanceY
if(whichIt.style.pixelTop <document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop
if(whichIt.style.pixelLeft <document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft
if(whichIt.style.pixelLeft >document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20
if(whichIt.style.pixelTop >document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5
event.returnValue = false
} else {
whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY)
if(whichIt.left <0+self.pageXOffset) whichIt.left = 0+self.pageXOffset
if(whichIt.top <0+self.pageYOffset) whichIt.top = 0+self.pageYOffset
if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17
if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17
return false
}
return false
}
function dropIt() {
whichIt = null
if(NS) window.releaseEvents (Event.MOUSEMOVE)
return true
}
<!-- DRAG DROP CODE -->
if(NS) {
window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN)
window.onmousedown = grabIt
window.onmousemove = moveIt
window.onmouseup = dropIt
}
if(IE) {
document.onmousedown = grabIt
document.onmousemove = moveIt
document.onmouseup = dropIt
}
if(NS || IE) action = window.setInterval("heartBeat()",1)
</script>
<p><b>题库 </b></p>
<p>请在右边的搜索框中查找在此页面查找<br>
<br>
"馒头是谁发明的?","诸葛亮",<br>
"“蚕蚁”是蚂蚁还是蚕?","蚕",<br>
"古诗的体制称为“风雅颂”,其中“颂”是指:","宗庙乐歌",<br>
" 目前,唯有哪个金融机构可在县一级的地方设立分支机构?","中国农业银行",<br>
"东汉末年我国的一位杰出的医学家是:","华佗",<br>
"离地面越高空气越稀薄是因为:","空气受到地球引力的影响",<br>
</P>
</body>
</>
<iframe id="baiduframe" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0"framespacing="0" frameborder="0" scrolling="no" width="468" height="50"
src="http://unstat.baidu.com/bdun.bsc?tn=chenyingkm2z&csid=101&rkcs=0&bgcr=FFFFFF&ftcr=000000&rk=1&bd=0&bdas=0">
</iframe>
自己可以修改这个代码框的尺寸。详细看网页:http://blog.csdn.net/sjz168/article/details/6690950
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)