Front/JS & jQuery
[js] location.origin
오선지♬
2025. 7. 10. 20:30
728x90
반응형
location.origin은 현재 웹 페이지의 **기본 URL(= 출처, origin)**을 의미합니다.
즉, 프로토콜 + 호스트 + 포트 번호로 구성된 문자열입니다.
✅ location.origin 구성 요소
| 구성 요소 | 예시 |
| location.protocol | "https:" 또는 "http:" |
| location.hostname | "example.com" 또는 "localhost" |
| location.port | ":8080" (포트가 있을 경우) |
| 전체 조합 (origin) | "https://example.com" 또는 "http://localhost:8080" |
✅ 예시
예 1: 기본 포트
URL: https://example.com/path/page.html
location.origin // "https://example.com"
예 2: 사용자 정의 포트
URL: http://localhost:3000/page
location.origin // "http://localhost:3000"728x90
반응형