一个浏览器主页

2022.07.31 15:08 | 访问量:


搜索引擎我用的是Bing,可以改成其他

支持点击按钮搜索或者回车搜索

可以加一些东西做成自己的浏览器主页

svg图是去阿里的图标库里找的,你也可以换成其他的

下面是Demo和代码:

Demo
我的主页

直接引用下面两个就好了:


<link rel="stylesheet" href="https://muxmus.com/css/search.css">
<script src="https://muxmus.com/js/search.js"></script>
				

ps:search.js文件可能需要引用在正文中,也就是<body>和</body>之间

下面是带注释讲解的js代码


// JavaScript Document
document.write("<div class=\"divm\">");
document.write("	<input type=\"text\" value=\"\" id=\"search\" />");
document.write("	<div class=\"divin\">");
document.write("		<img onClick=\"getinput()\" alt=\"搜索\" id=\"ss\" src=\"/img/search.svg\" />");
document.write("	</div>");
document.write("</div>");
function getinput(){
	var con = document.getElementById('search').value;
	window.location.href=("//cn.bing.com/search?q=" + con);
	//如果要用其他搜索引擎可以更改这里
	//如百度则改成“ window.location.href=("//www.baidu.com/s?wd=" + con); ”
}
$("#search").bind("keydown",function(e){
	let theEvent = e || window.event;
	let keyCode = theEvent.keyCode || theEvent.which || theEvent.charCode;
	if (keyCode == 13){
	//这里的13是回车,你也可以改成其他键
		getinput();
	}
});