How to bind a handler to a selection change on window?

后端 未结 3 1466
时光说笑
时光说笑 2020-12-09 05:02

Basically I need to know when the window.getSelection() has changed and bind a handler to this event. Ideas?

OBS: Please note that I\'m not looking to b

3条回答
  •  执笔经年
    2020-12-09 05:28

    There is no cross-browser event for that.

    However, there does exist an event called selectionchange, which trigger on every change in a selection in the document, but it is only supported in IE and recent WebKit (Chrome/Safari), so no Firefox/Opera.

    You can use the selectionchange event like this:

    $(document).on('selectionchange', function(e) {
        console.log('selectionchange', e.originalEvent); 
    });
    

    jsfiddle example

提交回复
热议问题