Window: find() method

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

Note: Support for Window.find() might change in future versions of Gecko. See Firefox bug 672395.

The Window.find() method finds a string in a window sequentially.

Syntax

js
find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)

Parameters

string

The text string for which to search.

caseSensitive

A boolean value. If true, specifies a case-sensitive search.

backwards

A boolean value. If true, specifies a backward search.

wrapAround

A boolean value. If true, specifies a wrap around search.

wholeWord

A boolean value. If true, specifies a whole word search.

searchInFrames

A boolean value. If true, specifies a search in frames.

showDialog

A boolean value. If true, a search dialog is shown.

Return value

true if the string is found; otherwise, false.

Examples

HTML

html
<p>Apples, Bananas, and Oranges.</p>
<button type="button" id="find-apples">Search for Apples</button>
<button type="button" id="find-bananas">Search for Bananas</button>
<button type="button" id="find-orange">Search for Orange</button>
<p id="output"></p>

JavaScript

js
function findString(text) {
  document.querySelector("#output").textContent = `String found? ${window.find(
    text,
  )}`;
}

document.getElementById("find-apples").addEventListener("click", () => {
  findString("Apples");
});
document.getElementById("find-bananas").addEventListener("click", () => {
  findString("Bananas");
});
document.getElementById("find-orange").addEventListener("click", () => {
  findString("Orange");
});

Result

Notes

In some browsers, Window.find() selects (highlights) the found content on the site.

Specifications

This is not part of any specification.

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
find
Non-standard
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 3 (Release date: 2007-10-26)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
Deno – No support
Deno
footnote No support

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.