IT tech Coding/ajax
ajax 해시, 특정한 부분으로 접근할때 필요한 것
Coding Life
2019. 6. 29. 10:03
해시의 기능을 아시나요?
html 웹페이지를 작성할때 특정한 부분으로 점핑할때 해시의 기능을 사용합니다.
a.html#three
<p id="three">
헬로....
위의 주소 a.html#three 이렇게 주소를 입력하면
헬로가 화면에 나오겠죠.... 아니 제일 위로 나옵니다.
id로 지정된 곳으로 이동한다는 것이네요.
해시기능은 일종의 책갈피의 기능이 아닐런지요~
<script>
if(location.hash) {
console.log(location.hash);
} else {
}
</script>
#three 여기서 #표시를 없애고 가져오고 싶다면?
console.log(location.hash.substr(1));
이런식으로 해시가 뭔지를 가지고 프로그램을 응용할 수 있습니다.
풀 주소인경우, location:8080/idex.html#javascript
fetchpage(location.hash.substr(2));
이렇게 하면 three란 단어를 가져옵니다.
반응형