매번 쓰기 귀찮아서 적어놓는다.
<script>
function getContextPath() {
var hostIndex = location.href.indexOf( location.host ) + location.host.length;
return location.href.substring( hostIndex, location.href.indexOf('/', hostIndex + 1) );
};
$(document).ready(function(){
/*alert(getContextPath());*/
}) ;
</script>
JSP 에서는,
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
이렇게 정의한 뒤에 <script src="${contextPath}/js/navi.js"></script>
이런식으로 사용
'개발 > JavaScript' 카테고리의 다른 글
문자열 감별 함수 isNaN (0) | 2018.04.08 |
---|---|
apply() (0) | 2018.02.13 |
js 파일...읽어랏~ (0) | 2018.02.13 |
브라우저 별로 다른 버전 js 사용하기 (0) | 2018.02.13 |
js 파일 사용시 한글 깨짐 (0) | 2018.02.13 |