IE 11 document.selection does not work [closed]

2019-04-16 09:20发布

问题:

I am trying to deselect selected content in HTML editor.

I have used selection.empty() function for deselecting content it is working fine up to IE10 but it is not working in IE11. Also the create function is not working in IE11

Is there any alternative function for this?

回答1:

IE11 replaced the legacy API with a more standards-compliant API.

selection is no longer supported. Starting with Internet Explorer 11, use getSelection.

See Compatibility changes in IE11.

An HTMLSelection object is now returned, which is different to the old selection object and it doesn't look like empty is a valid method in the new API. Hopefully the new API will have methods that allow you to perform the same logic.