博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
百家搜索:在网站中添加Google、百度等搜索引擎
阅读量:4286 次
发布时间:2019-05-27

本文共 4596 字,大约阅读时间需要 15 分钟。

来源:

看到一些网站上添加了各种搜索引擎。如Google、百度、360、有道等,就有点好奇,这个怎么实现?研究了一各个搜索引擎怎么传送关键字,找到了小窍门,于是乎,自家弄了一个百家搜索:

效果:

演示地址戳此:

ps:在列表中添加了糯米汇()的站内搜索,仅用于演示,别无它用,特此声明。

HTML代码:

  • 百度
  • 百度
  • 谷歌
  • 必应
  • 有道
  • 搜搜
  • 搜狗
  • 360
  • 爱淘宝
  • 亚马逊
  • 当当
  • 知道
  • 维基
  • Crea
  • 糯米汇

出处:淡忘~浅思

 

JavaScript:

window.onload = function()        {            var selectul = document.getElementById('selectul');            var lis = selectul.getElementsByTagName('li');            var selectedli = document.getElementById('selectedli');            var findParam = document.getElementById('findParam');            var sform = document.getElementById("sform");            var lislen = lis.length;            for (var i = 0; i < lislen; i++) {                lis[i].οnmοuseοver=function()                {                    selectul.style.overflow = "visible";                };                lis[i].οnmοuseοut=function()                {                    selectul.style.overflow = "hidden";                };                lis[i].onclick = function()                {                    selectedli.innerHTML = this.innerHTML;                    switch(this.innerHTML)                    {                        case "百度":                             findParam.name='wd';                             sform.action = "http://www.baidu.com/s";                             break;                        case "谷歌":                             findParam.name='q';                              sform.action = "http://www.google.com.hk/search";                             break;                        case "必应":                             findParam.name='q';                              sform.action = "http://cn.bing.com/search";                             break;                        case "有道":                             findParam.name='query';                              sform.action = "http://www.sogou.com/web";                             break;                        case "搜搜":                             findParam.name='w';                              sform.action = "http://www.soso.com/q";                             break;                        case "搜狗":                             findParam.name='q';                              sform.action = "http://www.youdao.com/search";                             break;                        case "360":                             findParam.name='q';                              sform.action = "http://www.youdao.com/search";                             break;                        case "爱淘宝":                             findParam.name='key';                              sform.action = "http://ai.taobao.com/search/index.htm";                             break;                         case "亚马逊":                             findParam.name='field-keywords';                              sform.action = "http://www.amazon.cn/s/ref=nb_sb_noss";                             break;                         case "当当":                             findParam.name='key';                              sform.action = "http://search.dangdang.com/";                             break;                         case "知道":                             findParam.name='word';                              sform.action = "http://zhidao.baidu.com/search";                             break;                         case "维基":                             findParam.name='search';                              sform.action = "ttp://zh.wikipedia.org/w/index.php";                             break;                         case "Crea":                             findParam.name='q';                              sform.action = "http://search.creativecommons.org/";                             break;                         case "糯米汇":                             findParam.name='s';                              sform.action = "http://www.nuomihui.com/";                             break;                    }                    selectul.style.overflow = "hidden";                };                };        };

下一篇:

你可能感兴趣的文章
怎么做前端fiddle代理
查看>>
轻松自动化---selenium-webdriver(python) (三) 简单元素的定位
查看>>
selenium python 常用方法总结
查看>>
轻松自动化---selenium-webdriver(python) (五)---层级定位
查看>>
selenium+Python 上传文件
查看>>
python+selenium 上传文件或者图片
查看>>
轻松自动化---selenium-webdriver(python) (四)--如何定位一组元素?
查看>>
selenium-webdriver(python) (七)-----多层框架或窗口的定位
查看>>
selenium多个窗口切换
查看>>
python selenium下载电子书
查看>>
基于python的selenium实现多窗口切换
查看>>
H5和flash的区别
查看>>
selenium-webdriver(python) (十)
查看>>
selenium借助AutoIt识别上传(下载)详解
查看>>
轻松自动化---selenium-webdriver(python) (十二)--转自虫师
查看>>
自动化测试 -- 通过Cookie跳过登录验证码
查看>>
自动化测试如何解决验证码的问题
查看>>
在做自动化测试之前你需要知道的
查看>>
API 是什么
查看>>
python27与python35可以共存
查看>>