JS Cookbook - Get Highlighted Text

Makale İçerik Listesi

Coding

  1. function getSelection() {
       var text = "";
       if (window.getSelection) {
           text = window.getSelection().toString();
       }
       return text;
    }
    
    document.onselectionchange = function() {
      document.getElementById("sel").value = getSelectionText();
    };

Kaynak

  1. Stackoverflow - link
  2. Caniuse getSelection - link