Selection.addRange()已弃用,并将从Chrome中删除 [英] Selection.addRange() is deprecated and will be removed from Chrome

查看:2267
本文介绍了Selection.addRange()已弃用,并将从Chrome中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在使用 aloha编辑器时在Chrome的控制台日志中注意到以下消息:

$ b.b


aloha.js:14579 - Selection.addRange()合并现有范围和指定范围的行为已被弃用,并将于2017年4月左右在M58中删除。有关详细信息,请参见 https://www.chromestatus.com/features/6680566019653632 。 p>

在试图找到替代品时,除了要删除它之外,我找不到任何东西,所以我想知道是Selection.addRange()的替代方法来摆脱此消息。 诀窍是使用<$ c $在使用 addRange(range)添加新范围之前,在您的选择上使用c> removeAllRanges()。下面是使用它来选择 elem 的所有内容的示例:

  selection = window.getSelection(); //保存选择。 
range = document.createRange();
range.selectNodeContents(elem);
selection.removeAllRanges(); //从选区中删除所有范围。
selection.addRange(range); //添加新的范围。


I recently noticed the following message in chrome's console log, while using aloha editor:

aloha.js:14579 - The behavior that Selection.addRange() merges existing Range and the specified Range is deprecated and will be removed in M58, around April 2017. See https://www.chromestatus.com/features/6680566019653632 for more details.

While trying to find a replacement, i couldn't find anything besides that they are going to remove it, so i would like to know what are the alternatives for Selection.addRange() to get rid of this message.

解决方案

The trick is to use removeAllRanges() on your selection before adding your new range using addRange(range). Here is an example when using it to select all content of elem:

selection = window.getSelection();    // Save the selection.
range = document.createRange();
range.selectNodeContents(elem);
selection.removeAllRanges();          // Remove all ranges from the selection.
selection.addRange(range);            // Add the new range.

这篇关于Selection.addRange()已弃用,并将从Chrome中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆