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
반응형

'Front > JS & jQuery' 카테고리의 다른 글

[js] URL 이동 및 히스토리 제어 메서드  (0) 2025.07.15
[js] location 속성별 설명  (0) 2025.07.14
[js] navigator.clipboard.writeText()  (0) 2025.07.09
[jQuery] .is()  (0) 2025.07.08
[jQuery] .has()  (0) 2025.07.07