Search code examples
javascriptjquerykeypress

Simulate keypress on document ready


I am new to JavaScript and jQuery and i want to make my own start page.

Unfortunately I will have to click the searchbar/omnibox (chrome) every time I want to search. Can I automate this with JavaScript/jQuery? Pressing F6 will focus on the search bar.

What I want: JavaScript/jQuery simulating F6 keypress on document ready. Code I did found that I can't get to work:

$(document).ready(function(){
$(jQuery.Event('keypress', {which: 117}));
});

117 is the keycode for F6.


Solution

  • You can't do this, simply because it's outside the scope of what a webpage should be doing and unsurprisingly Chrome prevents this behaviour.