PPRuNe Forums

PPRuNe Forums (https://www.pprune.org/)
-   Computer/Internet Issues & Troubleshooting (https://www.pprune.org/computer-internet-issues-troubleshooting-46/)
-   -   Adding search box to HTML document (https://www.pprune.org/computer-internet-issues-troubleshooting/651840-adding-search-box-html-document.html)

Discorde 15th March 2023 16:25

Adding search box to HTML document
 
Can any coding experts shed light on how to add a search box at the top when compiling an HTML document? There are plenty of suggested code sequences on the internet but with my very limited knowledge of coding I don't know which to use and I can't make any of them actually work. Viewing page source on other web pages for clues is too confusing and so doesn't help. If there is a simple solution I just need the HTML code and guidance as to where it should be inserted. Would it be between </head> and <body> ?

Thanks for info.


davidjohnson6 15th March 2023 18:11

I don't recall having seen anything going after </head> and before <body>
I'd stick it somewhere between <body> and </body>

Prop swinger 16th March 2023 00:07

It's just a simple html form that is either processed by some server side code in a file on your server or runs a javascript function that searches the document or the web.

Put it anywhere inside the <body> that you like.

Jhieminga 16th March 2023 11:03

Is it the page itself that you want to search? Or do you want to search the internet? I have used a Google form on my own site that enables you to search a specified website. See here for the details: https://programmablesearchengine.google.com/about/

Discorde 16th March 2023 21:49

Thanks Jhieminga. I should have been more specific - initially I wanted a search box to find text in a particular html doc and then if that worked add boxes in other items on my website.

I tried the Google code you suggested - the box appeared OK on the web page but returned 'No results' for any of the words I entered even though they featured in the text. Also lots of non-relevant links to ads appeared.

Jhieminga 17th March 2023 08:22

For the Google box to work, the pages you are searching must be visible on the internet and have been indexed by Google. When you set up the box, you can specify to search a specific domain and if that contains the document you mentioned, it should work. Yes, you will get additional 'results', it is Google after all....

Edit: searching a specific page is actually more complex than you would think. The challenge is in defining the range to be searched and storing that temporarily. You can also just put a snippet of text at the top to say 'Hit Ctrl-F to find what you want, or Cmd-F if you're on a Mac'.
There is an explanation of how it works in Javascript here: https://dev.to/am20dipi/how-to-build...avascript-4onf but that uses a pre-defined array of names as the search range.

Discorde 17th March 2023 11:52

Thanks Jhieminga. Surprisingly complicated! I use Kompozer for constructing HTML files. It has an edit 'Find . . . ' function which works on both the 'Normal' and 'Source' displays. It's a shame that there is no simple method of incorporating this in the file itself.

Jhieminga 17th March 2023 15:05

That is a functionality of the editor you're using. In a similar way every browser has a search function built into it that searches the current page. Both those pieces of software have the text to be searched in their 'memory' at the time, but a page itself doesn't have that. A browser is just a tool that displays, nothing more, if you want more functionality you have to decide whether to use server side processing or use a function built into the website that can be run on the viewer's side. We have a plethora of sites these days that appear to do a lot more than that, but this is heavily dependant on a lot of supporting software on the server side. It's not simple HTML anymore.


All times are GMT. The time now is 06:24.


Copyright © 2026 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.