Back to Content

FragmentDirective

files/en-us/web/api/fragmentdirective/index.md

latest1.3 KB
Original Source

{{APIRef("URL Fragment Text Directives")}}

The FragmentDirective interface is an object exposed to allow code to check whether or not a browser supports text fragments.

It is accessed via the {{domxref("Document.fragmentDirective")}} property.

Instance properties

None.

Instance methods

None.

Examples

Checking if text fragments are supported

The code below logs whether or not text fragments are supported in your browser by checking that {{domxref("Document.fragmentDirective")}} is defined. Note that the object is empty, and at present is mainly intended for feature detection. In the future, it might include other information.

html
<pre id="log"></pre>
js
const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = text;
}
css
#log {
  height: 20px;
}
js
if (document.fragmentDirective) {
  log("Your browser supports text fragments.");
} else {
  log("Text fragments are not supported in your browser.");
}

{{EmbedLiveSample("Checking if text fragments are supported","100%","30px")}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{cssxref("::target-text")}}