Click here to Skip to main content
14,327,936 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

Using the following code,we can call a function when key is pressed.
event.preventDefault()
Right after you catch the "F11" event
e.g:
if(event.keyCode == 122) {
event.preventDefault()
console.log('F11 was pressed');
}



But I need when button is clicked or javascript function is called,key function should be called as if I pressed the key.Just I want the reverse of the above example.We all know ctrl+f is for finding the text.In my application,when button is clicked,ctrl+f feature should be called.Therefore if I click the button,search textbox should be displayed in the web page as if I pressed the key.Thanks in advance
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can use jQuery even system to fake keypress events...
var e = jQuery.Event("keypress");
e.which = 122;
$("input").trigger(e);

input is the element on witch the even will be fired - change it according to your need...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100