Home  >  Article  >  Web Front-end  >  Introduction to compatibility writing method of Javascript selection_Basic knowledge

Introduction to compatibility writing method of Javascript selection_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:07:521442browse
复制代码 代码如下:

function getSelectedText() { //this function code is borrowed from: http://www.codetoad.com/javascript_get_selected_text.asp

var txt = "";
if (window.getSelection) {
txt = window.getSelection();
} else if (window.document.getSelection) {
txt = window.document.getSelection();
} else if (window.document.selection) {
txt = window.document.selection.createRange().text;
}
return txt;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn