Is it possible to simulate the keyboard shortcut Ctrl + F using jQuery?

I have a page with a lot of information in it, and it would be nice if the user clicked on the link and the browser search bar popped up, as if they had pressed Ctrl + F. I could query the database since there were informational names, but I do not want to reload the page when I click the link.

+6
source share
3 answers

Some browsers support window.find ()

+6
source

There are several plugins that allow you to do this, for example: https://github.com/jeresig/jquery.hotkeys

+2
source

I know this post is outdated, but I think I solved it with jquery:

//i am assuming you are searching through a table... //search input field listening for key pressed $('.search_input').keyup(function (e) { //listening if the key pressed is the enter button if (e.which === 13) { //inserting the value of textfield content, you can add if statement to check if the field is null or empty var search_param = $(this).val(); //value of field stored into a variable $('td').removeAttr('class'); //remove all classes attributed to a td AND search all td to find the one that march the search parameter if ($('td:contains("' + search_param + '")').html() !== undefined) { //if there is any td that has that record... then check for the closest tr and add a class with item_found as value $('td:contains("' + search_param + '")').closest('tr').attr('class', 'item_found'); //add some highlight to it. $('td:contains("' + search_param + '")').closest('tr').css({background:'yellow',color:black}); //then scroll to the item $(window).scrollTop($('.item_found').first().offset().top); } else { //if item is not found display no result found alert("Sorry no result found") } } }); 
+2
source

Source: https://habr.com/ru/post/896818/


All Articles