irv*_*a91 2 html javascript web-applications highlight
我正在制作一个 Web 应用程序,它将屏幕分成两个窗口,一侧是基于 Web 的文本编辑器,另一侧只是一个普通窗口。我正在尝试找到一种方法,使用户能够在浏览器端突出显示某些文本,然后将突出显示的文本自动保存到字符串中,然后我就可以在其中操作该字符串。
有人有什么想法吗?任何帮助将不胜感激。
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
$(document).ready(function (){
$('div').mouseup(function (e){
alert(getSelectionText())
})
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
Hello, this is a highlight text test
</div>Run Code Online (Sandbox Code Playgroud)