How get windows FIND() to work?

Aug 04, 2020 30 Replies

Environment: Win7.1 Firefox 78



Sample line used: Downhole Measurements



At least execution transfers from the calling HTML to the desired destination HTML.



BUT. the keyword does NOT get underlined or highlighted in any way. It would be particularly nice if all the keywords got highlighted and the first keyword was presented on the screen (think loong document and keyword was in middle).



Help?


Robert Baer:

If course not. Why should adding "?find=able" do that?

Technically calling "downhole-measurements.html?find=able" will just open the document referred by "downhole-measurements.html" and pass the querystring "find=able" to the server.

If the document was opened locally as file and not via HTTP then adding "?find=able" does nothing at all.

Then you need to build some server side script which reads the document and *adds* elements to highlight the places where the searched text was found. For example if you use PHP on the server the URL could be:

find.php?document=downhole-measurements.html&text=able

Then the script "find.php" will get the paramters "document" and "text", where "document" tells it which file to read and "text" which text to search for.

Arno Welzel https://arnowelzel.de

You won't get highlighting without adding Javascript.

I suggest you use a fragment identifier:

Downhole Measurements

because that gets passed to the browser, which will scroll to the matching tag. The fragment string is also available to Javascript by using

var fragment = location.hash; // Returns '#able'

You could use that to highlight the appropriate text.

Clifford Heath.

Does not that require EVERY instance of "able" in every document to be tagged? Or at minimum, the first instance to be tagged?

MUCH easier and saner to (somehow) get the browser FIND() to do its thing; even IE8 dew that.

Thanks

Robert Baer:

No.

You still need to write *code* to do this.

Then do it. What did you try so far? What's your problem with it?

Arno Welzel https://arnowelzel.de

"R.Wieser" wrote on 04 Aug 2020 in comp.lang.javascript:

Sounds like that approach requires me to edit a few thousand FINDs at minimum. What added fuss is required for the document?

Also, what does this find.php script look like?

Thamks

You mean "without adding Javascript" refers to the document. Adding matching tags all over the document is not sane; there are thousands of words needed to be found/highlighted.

Better to get the browser to do its thing; even IE8 does a nice brwser FIND().

Thanks

Robert Baer:

It will open the file, read the content, does a strpos() on the search term and add ... around the found word. You may also need to add the "found" CSS rule like this:

.found { background-color: #ff0; }

If you want to keep the URL "downhole-measurements.html?find=able" you can also do this with a script in the document itself which takes the URL (window.location.href), extracts the "find" parameter and calls either window.find() or walks the DOM tree to add a ... around the search hits - but in any case you need *code* to do the finding. There is no solution which just works by adding something to the URL.

Arno Welzel https://arnowelzel.de

Robert Baer:

[...]

So - why did you even ask in the first place when you already know the solution?

Arno Welzel https://arnowelzel.de

What is happening then depends on the user agent. It is NOT a general command to highlight something. HTML is NOT a programming language.

The FIND command of CMD.exe has *nothing to do* with HTML/JavaScript. JavaScript is *case-sensitive*. And ?window? is NOT ?windows?.

HTML is _NOT_ a programming language. HTML does NOT ?execute? and does NOT ?call?.

Of course not. HTML ? HyperText *Markup* Language ? is _NOT_ a programming language. To highlight something *in general*, you need a *programming* language.

-- downhole-measurements.html -----------------------------------

-- highlight.js ----------------------------------------------------------

/** * highlight.js ? Highlights occurrences of text in HTML documents * @author (C) 2020 Thomas 'PointedEars' Lahn * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License at * for more details. */

var highlight = { getNeedle: function () { /* Get value of value of ?find? parameter */ var value = (window.location.search.match(/[?&]find=([^&#]+)/) || [,]) [1]; if (value) value = decodeURIComponent(value); return value; },

focus: function (needle) { if (needle) { /* Focus first occurence */ if (typeof window.find != 'undefined' && !window.find(needle)) { if (typeof console != 'undefined' && typeof console.log != 'undefined') { console.log('Text not found: "' + needle + '"'); } } } },

highlight: function (needle) { if (needle) { /* Highlight all occurrences */ document.body.innerHTML = document.body.innerHTML.replace( new RegExp( /* slurp textareas and tags */ '((?:[^

Evertjan,

Thats the first time I've ever heard of it. Thanks.

Regards, Rudy Wieser

I know of no standard way that find-in-page behaviour can be automated.

CH

Clifford Heath:

That was already mentioned:

Arno Welzel https://arnowelzel.de

What part of "no standard way" is difficult to understand?

Clifford Heath:

Did I claim, that this is standard?

Arno Welzel https://arnowelzel.de

"R.Wieser" wrote on 05 Aug 2020 in comp.lang.javascript:

There has to be a first time for everything. Haha.

Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required