I can't think of a good use case for it, but


#1

I learned, yesterday, that it’s possible to get the value of highlighted text.

When was that implemented? I can’t think of a reason to use it, but I think it’s pretty cool. :rofl:

<html><head>
<script>
function alertme(){
var textarea = document.getElementById("textArea");  
var selection = (textarea.value).substring(textarea.selectionStart,textarea.selectionEnd);
alert (selection);
}
</script>
</head>
<body> 
<p><textarea class="noscrollbars" id="textArea"></textarea></p>
<button onclick="alertme()">Click me</button>
</body></html>

Type something in the textarea, highlight only part of it, and click the button. Works in FF, IE, and Edge.

V/r,

^ _ ^


#2

Clipboard manipulation. Context specific search-and-replace. There’s a couple of uses out there.


#3

Clipboard manipulation?? You can programmatically interfere with a systems clipboard???

V/r,

^ _ ^


#4

Yeah.

https://www.sitepoint.com/javascript-copy-to-clipboard/

Medium also has a “top highlight” feature which shows the text that was most often highlighted when reading a specific article.


#5

Kinda slick. AND, I’m glad that it can’t be arbitrary - according to the article, the user actually has to take action for it to work. I was worried that any code could copy a selection without the user’s knowledge.

Thank you.

V/r,

^ _ ^


#6

Well, you can get the contents of the users clipboard but most browsers will ask you to permit this first.