창 위치.href
예
현재 페이지의 URL 가져오기:
let url = location.href;
현재 페이지의 URL 설정:
location.href = "https://www.w3schools.com";
아래에 더 많은 예가 있습니다.
정의 및 사용
속성 은 location.href
현재 페이지의 전체 URL을 설정하거나 반환합니다.
통사론
href 속성을 반환합니다.
location.href
href 속성을 설정합니다.
location.href = URL
재산 가치
Parameter | Description |
URL |
An absolute URL like: http://www.example.com/default.htm A relative URL like default.htm An anchor URL like location.href="#top" A new protocol like: ftp://someftpserver.com mailto:[email protected] file://host/path/example.txt |
반환 값
유형 | 설명 |
문자열 | 프로토콜을 포함한 페이지의 전체 URL(예: https://). |
더 많은 예
페이지 내의 앵커를 가리키도록 href 값을 설정합니다.
location.href = "#top";
이메일 주소를 가리키도록 href 값을 설정합니다(새 이메일 메시지가 열리고 생성됨):
location.href = "mailto:[email protected]";
브라우저 지원
location.href
모든 브라우저에서 지원됩니다:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |