JavaScript

[Window_Object] JS - focus() 메서드 ★ - 윈도우창 포커스 설정 (= focus메서드 = 포커스메서드)

목차

  1. focus() 예제 - 지정 윈도우창 포커스 설정
  2. focus() 정의
  3. focus() 구문
  4. blur() 예제 - 현재창에서 포커스 제거
  5. focus() 예제 - 일정 시간 간격으로 다른 창으로 포커스 이동

 

focus() 예제 - 지정 윈도우창 포커스 설정

 

<button onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  var hz = window.open("", "", "width=200,height=100");

  hz.document.write("<p>홈짱닷컴 Homzzang.com</p>");

  hz.focus();

}

</script>

 

결과보기

 

focus() 정의

 

지정 윈도우창에 포커스 설정.

※ 포커스 설정 시, 여러 윈도우창 중 맨 앞으로 보내짐.

 


 

1. cf.

blur() 메서드 - 지정 윈도우창에서 포커스 제거.

 

2. 주의

이 메서드는 현재 창을 배경으로 가져오도록 요청함. 그 결과,

사용자 설정 달라서 모든 브라우저에서 예상대로 작동 안 할 수도 있음.

 

3.

모든 브라우저 지원

 

 

focus() 구문

 

window.focus()

 


[매개변수]

 

없음.

 


[반환값]

 

없음.

 

 

blur() 예제 - 현재창에서 포커스 제거

 

<button onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  var hz = window.open("", "", "width=200, height=100");

  hz.document.write("<p>홈짱닷컴 Homzzang.com</p>");

  hz.blur();

}

</script>

 

결과보기

 

focus() 예제 - 일정 시간 간격으로 다른 창으로 포커스 이동

※ 주의: 사용자 브라우저 설정 및 윈도우창에 연결된 사이트 설정에 따라 정상작동 안 할 수도 있음.

 

<div>

    <span>홈짱닷컴 Homzzang.com</span>

</div>


<script>

var popups={

    naver:{},

    daum:{}

}

var focus='naver';

function brain_timeInterval(){    

    setInterval(function(){

        if(focus == 'naver'){

            popups.daum.focus();

            focus='daum';

        }else{

            popups.naver.focus();

            focus='naver';

        }

        console.log(focus);

    },3000);

}

function callNaver(){

    popups.naver = window.open('https://naver.com', 'id1',  'width=600, height=300, scrollbars, resizable');

}

function callDaum(){

    popups.daum = window.open('https://daum.net', 'id2',  'width=600, height=300, scrollbars, resizable');

}

 

//init();

 

area();

function area(){

    try{

        callNaver();

        callDaum();

        brain_timeInterval();   

    }catch(e){

        alert(e);

    }

}

</script>

 

결과보기

넓은마인드 님 (211028) https://sir.kr/qa/436350



분류 제목
DOM_Event_Object JS - StorageEvent 객체 - 윈도우창 저장영역 변경 (= 스토리지이벤트객체= 스토리지이벤트종류)
DOM_Event_Object JS - TouchEvent 객체 - 터치이벤트객체 (= 터치이벤트종류)
DOM_Event_Object JS - TransitionEvent 객체 - CSS 전환 실행 (= 트랜지션이벤트객체 = 트랜지션이벤트종류…
DOM_Event_Object JS - UiEvent 객체 - 유저인터페이스변환 (= 유아이이벤트객체 = 유저인터페이스이벤트종류 = 사용자…
DOM_Event_Object JS - WheelEvent 객체 - 마우스휠움직임 (= 휠이벤트객체)
API_Geolocation JS - coordinates -
API_Geolocation JS - position -
API_Geolocation JS - positionError -
API_Geolocation JS - positionOptions -
API_Geolocation JS - clearWatch() 메서드 -
API_Geolocation JS - getCurrentPosition() 메서드 -
API_Geolocation JS - watchPosition() 메서드 -
Window_History JS - history.length 속성 - history개수 (= 방문이력개수 = 방문주소개수 = 히스토리…
Window_History JS - history.back() 메서드 ★ - 이전페이지 가기
Window_History JS - history.forward() 메서드 - 다음페이지 가기
53/89
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 2
웹유틸
회원센터
홈짱닷컴 PC버전 로그인