<body onload="my_func()">
<p id="p"></p>
<textarea id="output" rows="25" cols="50"></textarea>
<br>
<input type="button" onclick="fclick()" value="скопировать выделение">
<script>
let elem = document.getElementById("p");
for (let i = 0; i < 100;i++){
elem.innerHTML += "my text";
}
function my_func(){
let range = new Range();
range.setStart(elem,0);
range.setEnd(elem,1);
document.getSelection().removeAllRanges();
document.getSelection().addRange(range);
}
function fclick(){
let selObj = window.getSelection();
let selectedText = selObj.toString();
let textoutput = document.getElementById("output");
textoutput.innerHTML = selectedText;
}
</script>
<body>
|