목차
- window.getSelection() 예제 - 사용자가 드래그 선택한 텍스트 얻기
- window.getSelection() 정의
- 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()