JavaScript

[Window_Object] JS - getSelection() 메서드 - 사용자에 의해 선택된 텍스트 범위 나타내는 선택객체 (IE9) ※ 사용자가 드래그 선택한 텍스트 얻기

목차

  1. window.getSelection() 예제 - 사용자가 드래그 선택한 텍스트 얻기
  2. window.getSelection() 정의
  3. window.getSelection() 구문

 

window.getSelection() 예제 - 사용자가 드래그 선택한 텍스트 얻기

 

// bm_text 얻기

document.getElementById('bo_v_con').addEventListener('contextmenu', function(event) {

    var bm_text = window.getSelection().toString();

    console.log(bm_text);

});

 


PS. jQuery 경우

 

// bm_text 얻기

$('#bo_v_con').on('contextmenu', function(event) {

    var bm_text = window.getSelection().toString();

    console.log(bm_text);

});

 

 

window.getSelection() 정의

 

사용자에 의해 선택된 텍스트 범위 나타내는 선택객체.

 


 

1. 

window 객체에 속하는 메서드 임.

2.

주요 최신 브라우저 모두 지원.

3. MDN getSelection() 예제보기

https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection

 

 

window.getSelection() 구문

 

window.getSelection()
또는,
getSelection()

 



분류 제목
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버전 로그인