Document.location

Document.locationLocation 객체를 반환하는 읽기 전용 속성입니다. Location은 document의 URL에 대한 정보를 포함하고 해당 URL을 변경하거나 다른 URL을 로딩하는 메서드를 제공합니다.

Document.location은 읽기 전용 Location 객체지만, 문자열을 할당할 수도 있습니다. 즉, 대부분의 경우에 document.location을 문자열처럼 사용할 수 있습니다. document.location = 'http://www.example.com'document.location.href = 'http://www.example.com'와 동의어입니다. 만약 다른 문자열을 할당한다면 브라우저가 할당된 웹사이트를 로드합니다.

URL을 문자열로 가져오려면 읽기 전용 속성인 document.URL도 사용할 수 있습니다.

만약 현재 document가 브라우저 맥락이 아니라면 null을 반환합니다.

Location 객체

예제

js
console.log(document.location);
// Location 객체를 console에 출력

명세서

Specification
HTML Standard
# the-location-interface

브라우저 호환성

BCD tables only load in the browser

같이 보기