Last active
September 21, 2018 09:48
-
-
Save andreyshr/ffc2e03aa3aa6726cc9440da4b168e1e to your computer and use it in GitHub Desktop.
getSelectedText()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// функция для получение выделенного текста | |
function getSelectedText(){ | |
var text = ""; | |
if (window.getSelection) { | |
text = window.getSelection(); | |
}else if (document.getSelection) { | |
text = document.getSelection(); | |
}else if (document.selection) { | |
text = document.selection.createRange().text; | |
} | |
return text; | |
} | |
$(document).ready(function() { | |
// при нажатии на Ctrl + Enter | |
var isCtrl = false; | |
$(document).keyup(function (e) { | |
if(e.which == 17) isCtrl = false; | |
}).keydown(function (e) { | |
if(e.which == 17) isCtrl=true; | |
if(e.which == 13 && isCtrl == true) { | |
// получаем и показываем выделенный текст | |
alert(getSelectedText()); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment