I have embedded a page with a pdf and a button. I want that when user select some text from pdf and click on button then it should alert with the text that he/she has selected. Following is my code :
<html>
<head>
<script>
function getSelText(){
var txt = '';
if (window.getSelection) {
txt = window.getSelection();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
} else return;
//document.Editor.selectedtext.value = txt;
alert(txt);
console.log("Text = "+txt);
}
</script>
</head>
<body>
<input type="button" value="Get selection" onmousedown="getSelText()">
<embed src="SamplePDF.pdf" width="700px" height="650px" id="pdf" onblur="CopyToClipboard(this)">
</body>
</html>
I have tried this but this is only work for non-pdf data, please help me out.