StaticRange

由於本文件沒有此語言的翻譯版本,您閱讀的是英文版的內容。 幫助我們翻譯這篇文章!

The DOM StaticRange interface extends AbstractRange to provide a method to specify a range of content in the DOM whose contents don't update to reflect changes which occur within the DOM tree. It offers the same set of properties and methods as AbstractRange.

AbstractRange and StaticRange are not available from web workers.

Constructor

StaticRange()
Creates a new StaticRange object given the StaticRangeInit dictionary specifying the default values for its properties.

Properties

The properties below are inherited from its parent interface, AbstractRange.

StaticRange.collapsed Read only
Returns a Boolean value which is true if the range's start and end positions are the same, resulting in a range of length 0.
StaticRange.endContainer Read only
Returns the DOM Node which contains the ending point of the range. The offset into the node at which the end position is located is indicated by endOffset.
StaticRange.endOffset Read only
Returns an integer value indicating the offset into the node given by endContainer at which the last character of the range is found.
StaticRange.startContainer Read only
Returns the DOM Node which contains the starting point of the range (which is in turn identified by startOffset.
StaticRange.startOffset Read only
Returns an integer value indicating the offset into the node specified by startContainer at which the first character of the range is located.

Methods

StaticRange.toRange()
Returns a new Range object which describes the same range as the source StaticRange, but is "live" with values that change to reflect changes in the contents of the DOM tree.

Usage notes

A DOM range specifies a span of content in a document, potentially beginning inside one node (or element) and ending inside another one. Unlike a Range, a StaticRange represents a range which is fixed in time; it does not change to try to keep the same content within it as the document changes. If any changes are made to the DOM, the actual data contained within the range specified by a StaticRange may change. This lets the user agent avoid a lot of work that is unnecessary if the web app or site doesn't need a live-updating range.

Specifications

Specification Status Comment
DOM
The definition of 'StaticRange' in that specification.
Living Standard
Static Range
The definition of 'StaticRange' in that specification.
Editor's Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
StaticRangeChrome Full support 60Edge Full support 18Firefox Full support 69
Notes
Full support 69
Notes
Notes In Firefox, StaticRange can currently only be used by browser-internal code or code with enhanced permissions; it is not yet exposed to the web.
IE No support NoOpera Full support 47Safari Full support 10.1WebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS Full support 10.3Samsung Internet Android Full support Yes
StaticRange() constructorChrome Full support 60Edge Full support 18Firefox No support NoIE No support NoOpera Full support 47Safari No support NoWebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS No support NoSamsung Internet Android Full support Yes
collapsedChrome Full support 60Edge Full support 18Firefox Full support 69IE No support NoOpera Full support 47Safari Full support 10.1WebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS Full support 10.3Samsung Internet Android Full support Yes
endContainerChrome Full support 60Edge Full support 18Firefox Full support 69IE No support NoOpera Full support 47Safari Full support 10.1WebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS Full support 10.3Samsung Internet Android Full support Yes
endOffsetChrome Full support 60Edge Full support 18Firefox Full support 69IE No support NoOpera Full support 47Safari Full support 10.1WebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS Full support 10.3Samsung Internet Android Full support Yes
startContainerChrome Full support 60Edge Full support 18Firefox Full support 69IE No support NoOpera Full support 47Safari Full support 10.1WebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS Full support 10.3Samsung Internet Android Full support Yes
startOffsetChrome Full support 60Edge Full support 18Firefox Full support 69IE No support NoOpera Full support 47Safari Full support 10.1WebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS Full support 10.3Samsung Internet Android Full support Yes
toRange()Chrome Full support 60Edge Full support 18Firefox No support NoIE No support NoOpera Full support 47Safari No support NoWebView Android Full support 60Chrome Android Full support 60Firefox Android No support NoOpera Android Full support 44Safari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

See also

  • Live updating range of content within the DOM: Range
  • AbstractRange, the abstract interface from which all ranges are derived