window 객체는 JavaScript의 위치 객체를 포함합니다. 다음 속성을 포함합니다 -
window.location.href
현재 페이지의 URL을 반환합니다.
예시
<!DOCTYPE html>
<html>
<body>
<p>Click below to get the complete URL of the page.</p>
<button onclick = "display()">URL</button>
<script>
function display() {
var res = location.href;
document.write(res);
}
</script>
</body>
</html> window.location.replace
현재 문서를 대체하는 데 사용됩니다.
예시
<!DOCTYPE html>
<html>
<body>
<button onclick = "display()">Replace current document</button>
<script>
function display() {
location.replace("https://www.qries.com")
}
</script>
</body>
</html> window.location.assign
새 문서를 로드하려면 JavaScript 할당을 사용하세요.
예시
<!DOCTYPE html>
<html>
<body>
<button onclick = "display()">Open new document</button>
<script>
function display() {
location.assign("https://www.qries.com")
}
</script>
</body>
</html>