Search Engine tip: Please put the full angle of the state of the <> into a half-width state of <> use
Many personal site owners want to build a site for their own website search engine, but not familiar with ASP, PHP, JSP and other dynamic development technology, the other set up their own site search also need space to support the corresponding dynamic technology, so often forced to give up. In fact, why not use Google to build a site search engine, to facilitate users of their website content to find.
If you want to search for specific content within a particular Web site (such as the content of the keyword "network" in the search www.cfan.com.cn), simply type in the Google search field: "Network site:cfan.com.cn" (without quotes). If you set up a Google search bar directly on your site's web page, and then ask your visitors to query according to Google's format, wouldn't it be possible for Google to function as a search engine in its own station? But we certainly cannot ask users to specifically learn the format of Google's search for specific Web sites. So the author immediately associated with the use of JavaScript scripts to enable Google to receive the query keyword after the automatic addition of a similar "site:cfan.com.cn" string? The answer is certainly yes. In your website, you need to place the following code in the range of the <body> tags within the site of the search engine page:
<script type="text/javascript"> var domainroot="mysite.com"//个人站点域名,替换成你的网站的网址即可 function Gsitesearch(curobj){ curobj.q.value="site:"+domainroot+" "+curobj.qfront.value } </script> <form action="http://www.Google.com/search" method="get" > <p>站内搜索:<br /> <input name="q" type="hidden" /> <input name="qfront" type="text" style="width: 180px" /> <input type="submit" value="开始搜索"> </p> </form> The key part of the script is the Gsitesearch function. Statement: "Curobj.q.value=" site: "+domainroot+" "+curobj.qfront.value" means: the "site:" string + variable domainroot, space, the visitor filled in the keyword according to this merge. Not only does the search format conform to Google's language specifications, but it also adds to the friendliness of search functionality and does not require users to follow Google's search rules.
At this point, your professional site search engine is completed (see Figure 1 completed in the station engine).
If we are not only to search the content of this site, but also to enable visitors to search the brothers site or the content of this kind of site, how to modify it? Next we will do some promotion of the code we just made.
<script type="text/javascript"> function Gsitesearch(curobj){ var domainroot=curobj.domainroot[curobj.domainroot.selectedIndex].value curobj.q.value="site:"+domainroot+" "+curobj.qfront.value } </script> <form action="http://www.Google.com/search" method="get" > <p> <input name="q" type="hidden" /> <input name="qfront" type="text" style="width: 180px" /> <input type="submit" value="立刻搜索" /><br /><br /> 站点: <select name="domainroot"> <option value="www.mywebsite.net" selected="1">本站</option> <option value="www.friend1site.net">友站1</option> <option value="www.friend2site.net">友站2</option> </select> </p> </form> We just need to modify the Gsitesearch function slightly, the flexibility of the search can be greatly enhanced. Webmaster only need to delete and choose option, you can achieve multi-site content search (see Figure 2 support multi-site search engine).
The little one says: Sometimes powerful features don't need to be a complex technology to achieve, but just a little inspiration and a little focus.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.