Does chrome supports document.selection?

后端 未结 3 781
天涯浪人
天涯浪人 2020-11-29 10:40

I am new to javascript, trying to perform:

document.selection.createRange();

but document.selection always returns unde

相关标签:
3条回答
  • 2020-11-29 11:10

    Try document.getSelection() or window.getSelection().

    Here's a quick example that I tested in chrome

    http://jsfiddle.net/hgDwx/

    0 讨论(0)
  • 2020-11-29 11:15

    Use window.getSelection(), which is the most cross-browser compatible (it's supported in the current versions of all major browsers) and is the standard. Chrome certainly supports it as fully as other browsers.

    document.selection should only be used for IE < 9.

    0 讨论(0)
  • 2020-11-29 11:25

    Use window.getSelection() instead.

    https://developer.mozilla.org/en/DOM/window.getSelection

    0 讨论(0)
提交回复
热议问题