--- title: GlobalEventHandlers.onselectionchange slug: Web/API/GlobalEventHandlers/onselectionchange translation_of: Web/API/GlobalEventHandlers/onselectionchange ---
{{ApiRef('DOM')}}{{SeeCompatTable}}

GlobalEventHandlers.onselectionchange  属性表示当一个 {{event("selectstart")}} 事件被触发,比如在页面上选中文字变化时,会执行绑定的事件处理器

Syntax

obj.onselectionchange = function;

Example

var selection;

document.onselectionchange = function() {
  console.log('New selection made');
  selection = document.getSelection();
};

完整例子请参阅Key quote generator demo.

Specifications

Specification Status Comment
{{SpecName('Selection API','#dom-globaleventhandlers-onselectionchange','GlobalEventHandlers.onselectionchange')}} {{Spec2('Selection API')}} Initial definition.

Browser compatibility

{{Compat("api.GlobalEventHandlers.onselectionchange")}}

See also