[TIL] 현재 주소 URL 가져오기

Captainjack·2022년 1월 12일
0

TIL

목록 보기
128/258

window.location.href
// http://localhost:8080/contents?type=0

window.location.protocol
// http:

window.location.host
// localhost:8080

window.location.hostname
//localhost

window.location.port
//8080

window.location.pathname
// /contents

window.location.search
// ?type=0

var target = typeof window.location.href;
console.log(target);
// string

타입 검사해보면 문자열로 반환해줌
나는 여기서 끝에자리만 필요함.

var target = window.location.href.slice(-1);
console.log(target);
// 0 whatever

출처

https://hianna.tistory.com/464

profile
til' CTF WIN

0개의 댓글