Skip to content

Instantly share code, notes, and snippets.

@ambrosiora
Last active February 19, 2019 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambrosiora/985e5bca2d7e4a937d7323ca1185b0a6 to your computer and use it in GitHub Desktop.
Save ambrosiora/985e5bca2d7e4a937d7323ca1185b0a6 to your computer and use it in GitHub Desktop.
Texto selecionado na página
<!DOCTYPE html>
<html>
<head>
<title>teste</title>
</head>
<body>
<p id="paragrafo">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</body>
</html>
<script type="text/javascript">
document.getElementById('paragrafo').addEventListener('mouseup', function(event) {
var text = getSelectedText();
if(text){
alert(text);
}
});
function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.selection) {
return document.selection.createRange().text;
}
return '';
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment