How does javascript get the value selected by the cursor and replace it?

question: how to implement text selection and replace worthwhile functions similar to rich text editors?

 var word = window.getSelection?window.getSelection():document.selection.createRange();
 alert(word); 

using the above api, you can get the selected value, but how do you get the exact location of the selected value and replace it?


window.getSelection().baseNode.data=''

there is a common effect of selecting content with copyright notices. It feels like this need of yours.

$('body').on('copy', function (e) {

  if (typeof window.getSelection == 'undefined') {

    return;
  }

  var body_element = document.body,
      selection = window.getSelection();

  if (('' + selection).length < 30) {

    return;
  }

  var newdiv = document.createElement('div');

  newdiv.style.position = 'absolute';

  newdiv.style.left = '-99999px';

  body_element.appendChild(newdiv);

  newdiv.appendChild(selection.getRangeAt(0).cloneContents());

  if (selection.getRangeAt(0).commonAncestorContainer.nodeName == 'PRE') {

    newdiv.innerHTML = '
' + newdiv.innerHTML + '
'; }; Newdiv.innerHTML + ='
the copyright belongs to the author.
for commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source.
original: '+ location.href +' abcde.com'; Selection.selectAllChildren (newdiv); Window.setTimeout (function () { Body_element.removeChild (newdiv); }, 200);
)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7aa856-28c3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7aa856-28c3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?