私はhtml + javascript + jQueryを初めて使用します。選択したテキストを取得するために window.getSelection を使用しようとしていますが、これは機能していません。誰でもこれに対する解決策を提案できますか?
前もって感謝します。
私はhtml + javascript + jQueryを初めて使用します。選択したテキストを取得するために window.getSelection を使用しようとしていますが、これは機能していません。誰でもこれに対する解決策を提案できますか?
前もって感謝します。
試す
function getSelected() {
var text = "";
if (window.getSelection && window.getSelection().toString() && $(window.getSelection()).attr('type') != "Caret") {
text = window.getSelection();
return text;
} else if (document.getSelection && document.getSelection().toString() && $(document.getSelection()).attr('type') != "Caret") {
text = document.getSelection();
return text;
} else {
var selection = document.selection && document.selection.createRange();
if (!(typeof selection === "undefined") && selection.text && selection.text.toString()) {
text = selection.text;
return text;
}
}
return false;
}