HTML Window top 속성은 현재 창의 최상위 브라우저 창을 반환합니다.
구문
다음은 구문입니다 -
window.top
HTML 창 상단 속성의 예를 살펴보겠습니다 -
예시
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%) no-repeat;
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 30%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
.show{
font-size:1.2rem;
}
</style>
<body>
<h1>HTML Window top Property Demo</h1>
<button onclick="create()" class="btn">Check current window is topmost</button>
<div class="show"></div>
<script>
function create(){
if(window.top === window.self){
document.querySelector('.show').innerHTML='The current window is the topmost window';
} else{
document.querySelector('.show').innerHTML='The current window is not the topmost window';
}
}
</script>
</body>
</html> 출력

"현재 창이 맨 위에 있는지 확인을 클릭합니다. ” 버튼을 눌러 현재 창이 최상위 창인지 확인:
