回答編集履歴
1
markdown修正
answer
CHANGED
@@ -4,4 +4,9 @@
|
|
4
4
|
`doc.getSelection()` は selection オブジェクトを返す為、`String#replace` を持ちません。
|
5
5
|
`doc.getSelection().toString()` で期待通りの結果になるでしょう。
|
6
6
|
|
7
|
-
また、標準は `getSelection()` なので
|
7
|
+
また、標準は `getSelection()` なので `getSelection()` を優先した方が良いと思います。
|
8
|
+
|
9
|
+
```JavaScript
|
10
|
+
var doc = document,
|
11
|
+
txt = typeof doc.getSelection === 'function' ? doc.getSelection().toString() : doc.selection.createRange().text;
|
12
|
+
```
|