Get the Highlighted/Selected text

后端 未结 5 1555
無奈伤痛
無奈伤痛 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:19

    Yes you can do it with simple HMTL snippet:

    document.addEventListener('mouseup', event => {  
        if(window.getSelection().toString().length){
           let exactText = window.getSelection().toString();        
        }
    }
    

提交回复
热议问题