Document.hasFocus()
메소드는 문서 또는 문서 내의 요소(element) 중 어느 하나라도 포커스(focus)를 갖고 있으면 true,
그렇지 않으면 false
인 Boolean
값을 반환한다. 이 메소드를 사용하여 문서내 활성화된(active) 요소가 포커스를 갖고 있는지 판단할 수 있다.
focused = document.hasFocus();
문서 내의 활성화된 요소가 포커스를 갖고 있지 않으면 false
를 반환, 포커스를 갖고 있다면 true
를 반환
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>TEST</title>
<style>
#message { font-weight: bold; }
</style>
<script>
setInterval( CheckPageFocus, 200 );
function CheckPageFocus() {
var info = document.getElementById("message");
if ( document.hasFocus() ) {
info.innerHTML = "The document has the focus.";
} else {
info.innerHTML = "The document doesn't have the focus.";
}
}
function OpenWindow() {
window.open (
"http://developer.mozilla.org/",
"mozdev",
width=640,
height=300,
left=150,
top=260
);
}
</script>
</head>
<body>
<h1>JavaScript hasFocus example</h1>
<div id="message">Waiting for user action</div>
<div><button onclick="OpenWindow()">Open a new window</button></div>
</body>
</html>
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'Document.hasFocus()' in that specification. | Living Standard | Initial definition |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 30 | 3.0 (1.9) | 6.0 | Not supported | (Yes) |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 1.0 (1.9) | ? | Not supported | ? |
Action Script 2.0 기초 (0) | 2021.02.18 |
---|---|
Flash Builder - Air Launchpad (0) | 2018.09.09 |
HTML5 소개 (0) | 2018.09.04 |
JavaScript - 현재 페이지의 URL 가져오기 (0) | 2018.09.04 |
REN 명령어 - 파일 이름 변경 (0) | 2017.12.10 |
댓글 영역