1 function getSelectedText() {
 2   if (window.getSelection) {
 3     // This technique is the most likely to be standardized.
 4     // getSelection() returns a Selection object, which we do not document.
 5     return window.getSelection().toString();
 6   }else if (document.getSelection) {
 7     // This is an older, simpler technique that returns a string
 8     return document.getSelection();
 9   }else if (document.selection) {
10     // This is the IE-specific technique.
11     // We do not document the IE selection property or TextRange objects.
12     return document.selection.createRange().text;
13   }
14 }

相关文章: