Document:caretRangeFromPoint() 方法

非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!

Document 接口的 caretRangeFromPoint() 方法返回指定坐标位置文档片段的 Range 对象。

该方法是 Document.caretPositionFromPoint 方法的 WebKit 专有实现。

语法

js
caretRangeFromPoint(x, y)

参数

x

当前视口内的水平位置。

y

当前视口内的垂直位置。

返回值

以下之一:

  • 一个 Range
  • Null,当 xy 为负数,超出视口范围或者没有包含文本的节点。

示例

访问 Document.caretPositionFromPoint 页面查看此方法的实时示例。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
caretRangeFromPoint
Non-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.