Created
January 5, 2018 19:22
-
-
Save tashua314/b9aef96bed7e7d4df73388b2d640f359 to your computer and use it in GitHub Desktop.
複数のサイト内検索
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>複数サイト検索</title> | |
<!--CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> | |
<!--JS --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> | |
<!--自作CSS --> | |
<style type="text/css"><!-- | |
.container { | |
margin: 30px; | |
} | |
#disp_domains { | |
border: solid; | |
padding: 10px; | |
} | |
input { | |
margin-right: 10px; | |
} | |
input[type=text] { | |
width: 500px; | |
} | |
--></style> | |
<script type="text/javascript"> | |
$(function() { | |
// ready | |
var DOMAINS = [ // ここにサイトを追加してください | |
'qiita.com', | |
'www.hatena.ne.jp' | |
]; | |
var domains_param = ''; | |
var disp_html = ''; | |
$.each(DOMAINS, function(i, value) { | |
if (i == 0) { | |
domains_param = 'site:' + value; | |
disp_html = value + '<br>'; | |
} else { | |
domains_param += '+OR+site:' + value; | |
disp_html += value + '<br>'; | |
} | |
}); | |
$('#disp_domains').html(disp_html); | |
$("#submit").on("click", function() { | |
goSearch(); | |
}); | |
$("#text").on("keydown", function(e) { | |
if(e.keyCode === 13) { | |
goSearch(); | |
} | |
}); | |
// リダイレクト | |
function goSearch() { | |
var val = $("#text").val(); | |
window.location.href = 'http://google.com/search?q=('+domains_param+')+'+val; | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="form-group"> | |
<input id="text" type="text" placeholder="検索する画像のURL"> | |
<input type="button" value="検索" id="submit" class="btn btn-default"> | |
</div> | |
<div class="display"> | |
<label for="">検索対象URL</label> | |
<div id="disp_domains"></div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment