Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override browser's search feature (CTRL+F), but reuse its native search field

I would like to override CTRL+F in order to provide a custom search feature on a HTML page. This can easily be done with :

window.onkeydown = function(event) {
    if (event.ctrlKey && event.keyCode == 70) {
        event.preventDefault();          
        my_own_search();
    } }

but then I won't be able to use the browser's bottom native search field (example here with Firefox, French language) :

Description

How to do a custom search feature that reuses the browser's native bottam search textbox ?

If not possible, what do you suggest for creating a custom textbox sticked at the top right (like the Search bar in Chrome) or bottom (like the Search bar in Firefox), with Bootstrap for example ?


Another example : the PDF viewer in Chrome provides custom search (=not the regular search on HTML pages, but a search adapted for PDF documents) but with the browser's native search field:

enter image description here

like image 385
Basj Avatar asked Sep 23 '14 14:09

Basj


2 Answers

You should NEVER be able to override a browser feature from a website. If you can, it's a major security fault in the browser.

As has been mentioned, plugins can be written for individual browsers, but they must be installed by the user (i.e. they are giving permission for your override). Otherwise you're out of luck

like image 149
freefaller Avatar answered Sep 20 '22 20:09

freefaller


I suppose because this is an old thread, but the correct answer marked here is now invalid. I have seen this on two sites in the past two days, and I kind of love it. Codepen.io for one:

Command/Control+F when in the first pane, and you will see their custom search.

If you examine their code you can see they have custom events for it, do a 'Search All Files' in chrome dev tools (CDT) for CodeMirror-search-field

like image 22
webdevinci Avatar answered Sep 21 '22 20:09

webdevinci