How get windows FIND() to work?...

Clifford Heath <no.spam@please.net> wrote on 06 Aug 2020 in
comp.lang.javascript:

On 5/8/20 7:46 am, Evertjan. wrote:
\"R.Wieser\" <address@not.available> wrote on 04 Aug 2020 in
comp.lang.javascript:

Robert,

Sample line used:
a href=\"downhole-measurements.html?find=able\">Downhole Measurements
/a

I think you are looking for

a href=\"downhole-measurements.html#able\">Downhole Measurements< /a

with in that \"downhole-measurements.html\" document the following line
just above the \"able\" chapter

a name=\"able\"

(remove the spaces after the \"<\" symbols)

Regards,
Rudy Wieser

Google Chrome 84 and up, desktop and mobile,
let you highlight \"This text\" from the url-string:

https://example.org/page.html#:~:text=This%20text

Not Chrome \"Version 84.0.4147.89 (Official Build) (64-bit)\" for OS/X.

<https://www.henk-weltje.nl/index.php/oude-boekwerkjes/watermolens-in-
apeldoorn#:~:text=Tijdens%20het%20nadenken%20over%20een%20geschikt%
20onderwerp>

In Version 84.0.4147.105 (Official Build) (64-bit), it does,

as does my Chrome Mobile for Android .111 32b

================

You can even make a bookmark with:

javascript:(function()%7Bconst selectedText %3D getSelection().toString()%
3Bconst newUrl %3D new URL(location)%3BnewUrl.hash %3D %60%3A~%3Atext%3D%24%
7BencodeURIComponent(selectedText)%7D%60%3Bwindow.open(newUrl)%7D)()

... witch will make this url-string for you,
after highlighting the wanted text by mouse.


> Where is this feature documented, please?

Read it somewhere in the Dev-blog, I suppose,
or css-tricks perhaps.

--
Evertjan.
The Netherlands.
(Please change the x\'es to dots in my emailaddress)
 
Arno Welzel wrote:
Robert Baer:

[...]
Even IE8 FIND() works; highlights all found keywords dynamically,
allows previous/next.
Seems most browsers support this rather well.

So - why did you even ask in the first place when you already know the
solution?
I do NOT know the solution; requiring the user to enter
<Ctrl>f<desiredkeyword> is not a sane requirement,

Thanks
 
Clifford Heath wrote:
On 5/8/20 1:13 pm, Robert Baer wrote:
Clifford Heath wrote:
On 4/8/20 12:13 pm, Robert Baer wrote:
   Environment: Win7.1 Firefox 78

    Sample line used:
a href=\"downhole-measurements.html?find=able\">Downhole
Measurements</a

    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).

You won\'t get highlighting without adding Javascript.

I suggest you use a fragment identifier:

a href=\"downhole-measurements.html#able\">Downhole Measurements</a

because that gets passed to the browser, which will scroll to the
matching <a name=\"able\"> 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.
   You mean \"without adding Javascript\" refers to the document.
   Adding matching <a name=\"able\"> 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().

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

CH
Other than \"forcing\" a browser to doa nominally manual search, that
seems to be true.

However, the grand expert Thomas \'PointedEars\' Lahn may have given us
highlight.js as an answer

Thanks
 
Arno Welzel wrote:
Clifford Heath:

On 5/8/20 1:13 pm, Robert Baer wrote:
[...]
  Better to get the browser to do its thing; even IE8 does a nice
brwser FIND().

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

That was already mentioned:
https://developer.mozilla.org/en-US/docs/Web/API/Window/find
....and....i also mentioned to add all that in every document for
thousands of keywords into a goodly batch of documents is not exactly sane.

Thanks
 
Clifford Heath wrote:
On 5/8/20 9:54 pm, Arno Welzel wrote:
Clifford Heath:

On 5/8/20 1:13 pm, Robert Baer wrote:
[...]
    Better to get the browser to do its thing; even IE8 does a nice
brwser FIND().

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

That was already mentioned:
https://developer.mozilla.org/en-US/docs/Web/API/Window/find

What part of \"no standard way\" is difficult to understand?
Talk to \"moz\".
 
Arno Welzel wrote:
Clifford Heath:

On 5/8/20 9:54 pm, Arno Welzel wrote:
Clifford Heath:

On 5/8/20 1:13 pm, Robert Baer wrote:
[...]
  Better to get the browser to do its thing; even IE8 does a nice
brwser FIND().

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

That was already mentioned:
https://developer.mozilla.org/en-US/docs/Web/API/Window/find

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

Did I claim, that this is standard?
May i quote DIRECTLY from that site:
*QUOTE*
Non-standard
This feature is non-standard and is not on a standards track. Do not use
it on production sites facing the Web: it will not work for every user.
There may also be large incompatibilities between implementations and
the behavior may change in the future.

Note: Support for Window.find() might change in future versions of
Gecko. See bug 672395.
*END QUOTE*
 
Evertjan. wrote:
Clifford Heath <no.spam@please.net> wrote on 06 Aug 2020 in
comp.lang.javascript:

On 5/8/20 7:46 am, Evertjan. wrote:
\"R.Wieser\" <address@not.available> wrote on 04 Aug 2020 in
comp.lang.javascript:

Robert,

Sample line used:
a href=\"downhole-measurements.html?find=able\">Downhole Measurements
/a

I think you are looking for

a href=\"downhole-measurements.html#able\">Downhole Measurements< /a

with in that \"downhole-measurements.html\" document the following line
just above the \"able\" chapter

a name=\"able\"

(remove the spaces after the \"<\" symbols)

Regards,
Rudy Wieser

Google Chrome 84 and up, desktop and mobile,
let you highlight \"This text\" from the url-string:

https://example.org/page.html#:~:text=This%20text

Not Chrome \"Version 84.0.4147.89 (Official Build) (64-bit)\" for OS/X.

https://www.henk-weltje.nl/index.php/oude-boekwerkjes/watermolens-in-
apeldoorn#:~:text=Tijdens%20het%20nadenken%20over%20een%20geschikt%
20onderwerp

In Version 84.0.4147.105 (Official Build) (64-bit), it does,

as does my Chrome Mobile for Android .111 32b

================

You can even make a bookmark with:

javascript:(function()%7Bconst selectedText %3D getSelection().toString()%
3Bconst newUrl %3D new URL(location)%3BnewUrl.hash %3D %60%3A~%3Atext%3D%24%
7BencodeURIComponent(selectedText)%7D%60%3Bwindow.open(newUrl)%7D)()

.. witch will make this url-string for you,
after highlighting the wanted text by mouse.
* How could someone be so stupid as to 1) search a document for a
keyword first, then 2) construct a complex URL to FIND that keyword?

Where is this feature documented, please?

Read it somewhere in the Dev-blog, I suppose,
or css-tricks perhaps.
 
Robert,

* How could someone be so stupid as to 1) search a document for a keyword
first, then 2) construct a complex URL to FIND that keyword?

To help someone even more \"stupid\" ?

Being able to send a friend/granny/client an URL which causes the webpage
scroll to and hilite the phrase/line you want them to read an talk about
could be quite handy. Not everyone knows (or wants to know!) how to use
their webbrowser beyond clicking a link and scroll thru the result.

Heck, I could even emagine it being handy for myself as a way to \"bookmark\"
stuff on certain webpages, even on pages I\'ve stored locally.

Also, what makes you think that whomever wants to use such an URL needs to
construct it himself ? I could imagine a local page containing some JS
could do it. Also, plugins, other kinds of scripting (VBScript) and
programs. Just drop the URL and sought-for text into two input fields,
press the button and copy the result.

Regards,
Rudy Wieser
 
On 6/8/20 8:24 pm, Evertjan. wrote:
Clifford Heath <no.spam@please.net> wrote on 06 Aug 2020 in
comp.lang.javascript:

On 5/8/20 7:46 am, Evertjan. wrote:
\"R.Wieser\" <address@not.available> wrote on 04 Aug 2020 in
comp.lang.javascript:

Robert,

Sample line used:
a href=\"downhole-measurements.html?find=able\">Downhole Measurements
/a

I think you are looking for

a href=\"downhole-measurements.html#able\">Downhole Measurements< /a

with in that \"downhole-measurements.html\" document the following line
just above the \"able\" chapter

a name=\"able\"

(remove the spaces after the \"<\" symbols)

Regards,
Rudy Wieser

Google Chrome 84 and up, desktop and mobile,
let you highlight \"This text\" from the url-string:

https://example.org/page.html#:~:text=This%20text

Not Chrome \"Version 84.0.4147.89 (Official Build) (64-bit)\" for OS/X.

https://www.henk-weltje.nl/index.php/oude-boekwerkjes/watermolens-in-
apeldoorn#:~:text=Tijdens%20het%20nadenken%20over%20een%20geschikt%
20onderwerp

In Version 84.0.4147.105 (Official Build) (64-bit), it does,

Interestingly, it works for me now - I must have made an error yesterday.

Thanks.

CH
 
Robert Baer:

Arno Welzel wrote:
Clifford Heath:

On 5/8/20 9:54 pm, Arno Welzel wrote:
Clifford Heath:

On 5/8/20 1:13 pm, Robert Baer wrote:
[...]
  Better to get the browser to do its thing; even IE8 does a nice
brwser FIND().

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

That was already mentioned:
https://developer.mozilla.org/en-US/docs/Web/API/Window/find

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

Did I claim, that this is standard?


May i quote DIRECTLY from that site:
*QUOTE*
Non-standard

Exactly!

I did never say, that this is standard. I mentioned it so it is clear
that this is NOT standard!


--
Arno Welzel
https://arnowelzel.de
 
Robert Baer:

Arno Welzel wrote:
Robert Baer:

[...]
Even IE8 FIND() works; highlights all found keywords dynamically,
allows previous/next.
Seems most browsers support this rather well.

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


I do NOT know the solution; requiring the user to enter
Ctrl>f<desiredkeyword> is not a sane requirement,

Huh?

<https://arnowelzel.de/samples/find.html>

And to search for something there:

<https://arnowelzel.de/samples/find.html?find=voluptua>

This is just a rough \"quick & dirty\" example and uses window.find() and
URLSearchParams(). This is NOT standard and may NOT work with every
browser. It works for me with Firefox 79.0 and should also work with
most Chrome based browsers.

However - I would *not* recommend this for production. And for
highlighting *every* found word, adding next/prev etc. you need to
create your own script.



--
Arno Welzel
https://arnowelzel.de
 
Robert Baer amok-crossposted to alt.computer, comp.lang.javascript, and
sci.electronics.design

Evertjan. wrote:
You can even make a bookmark with:

javascript:(function()%7Bconst selectedText %3D
getSelection().toString()% 3Bconst newUrl %3D new
URL(location)%3BnewUrl.hash %3D %60%3A~%3Atext%3D%24%
7BencodeURIComponent(selectedText)%7D%60%3Bwindow.open(newUrl)%7D)()

The source code of this can be obtained with decodeURIComponent().
Formatted:

(function () {
const selectedText = getSelection().toString();
const newUrl = new URL(location);
newUrl.hash = `:~:text=${encodeURIComponent(selectedText)}`;
window.open(newUrl);
})();

BTW, this is an instance where using template strings is unnecessary:

newUrl.hash = \':~:text=\' + encodeURIComponent(selectedText);

suffices and is probably even more efficient.

>> .. witch will make this url-string for you,
^^^^^
_which_

after highlighting the wanted text by mouse.
* How could someone be so stupid as to 1) search a document for a
keyword first, then 2) construct a complex URL to FIND that keyword?

For sharing the highlighted variant of a Web site. There had been an add-
on/extension to do the same, but IIRC it became incompatible with newer
versions.

I have been thinking about doing something similar for a while, and now
I have gotten a good idea how to do it :)

F’up2 comp.lang.javascript

--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
 

Welcome to EDABoard.com

Sponsor

Back
Top