Get the Highlighted/Selected text

后端 未结 5 1561
無奈伤痛
無奈伤痛 2020-11-21 06:34

Is it possible to get the highlighted text in a paragraph of a website e.g. by using jQuery?

5条回答
  •  终归单人心
    2020-11-21 07:34

    Get highlighted text this way:

    window.getSelection().toString()
    

    and of course a special treatment for ie:

    document.selection.createRange().htmlText
    

提交回复
热议问题