오늘도 방구석에서
[Spring] 구글 검색 api 활용 - 검색창에 키워드 넣어주기 본문
프로젝트를 진행하다가
처음부터 구글 검색창을 보여 줄 것이 아니라
먼저 우리 홈페이지에서 검색을 해보고 검색 결과가 없으면 구글 검색창을 띄워주는 것으로 계획 변경 했다
<c:if test="${empty list}">
<div class="result-noList">
<h4>검색 키워드 : "${keyword}"</h4>
<br>
<h2>"${keyword}"에 대해 검색된 결과가 없습니다.</h2>
키워드는 ${keyword}를 받아와서 구글 검색창에 입력이 돼 있게끔 하는게 내 목표
그래서 사용자가 구글 검색을 원하면 검색 버튼만 누르면 되게 하는 것이다
<!-- 구글 서치 박스-->
<div>
<script>
(function() {
var cx = '';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx='
+ cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
//$('#gsc-i-id1').val('${keyword}');
//$('input[type="text"]').val('${keyword}');
</script>
<gcse:searchbox></gcse:searchbox>
<script>
window.onload = function() {
$('#gsc-i-id1').val('${keyword}');
};
</script>
</div>
<!-- 구글 서치 결과 나오는 곳 -->
<div>
<gcse:searchresults></gcse:searchresults>
</div>
</div>
</c:if>
'공부를 > Spring Framework' 카테고리의 다른 글
[Spring] 구글 검색 api 활용 - 구글 검색창과 홈페이지 검색창에 동시 입력 (0) | 2018.11.27 |
---|---|
[Spring] 구글 검색 api 활용 - 사용 시작 (0) | 2018.11.26 |
[spring] spring framework 설치 (0) | 2018.10.11 |