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?
Didn't find your answer? Ask the community — no account required.
A
Arno Welzel
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:
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
C
Clifford Heath
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.
with in that "downhole-measurements.html" document the following line just above the "able" chapter
(remove the spaces after the "
R
Robert Baer
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
A
Arno Welzel
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
E
Evertjan.
"R.Wieser" wrote on 04 Aug 2020 in comp.lang.javascript:
R
Robert Baer
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
R
Robert Baer
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
R
Robert Baer
A
Arno Welzel
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
A
Arno Welzel
Robert Baer:
[...]
So - why did you even ask in the first place when you already know the solution?
Arno Welzel
https://arnowelzel.de
T
Thomas 'PointedEars' Lahn
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.
/*** 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 */ '((?:[^
R
R.Wieser
Evertjan,
Thats the first time I've ever heard of it. Thanks.
Regards, Rudy Wieser
C
Clifford Heath
I know of no standard way that find-in-page behaviour can be automated.
CH
A
Arno Welzel
Clifford Heath:
That was already mentioned:
Arno Welzel
https://arnowelzel.de
C
Clifford Heath
What part of "no standard way" is difficult to understand?
A
Arno Welzel
Clifford Heath:
Did I claim, that this is standard?
Arno Welzel
https://arnowelzel.de
E
Evertjan.
"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)
C
Clifford Heath
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.