sharat87 / keyboard-fu

A chrome extension for all powerful hotkeys. This is a mirror repository to the original at https://bitbucket.org/sharat87/keyboard-fu
https://chrome.google.com/webstore/detail/cafiohcgicchdfciefpbjjgigbmajndb
29 stars 2 forks source link

focus() #4

Open rdewolff opened 10 years ago

rdewolff commented 10 years ago

Hi Sharat87

I'm trying to give focus to a particular object ID on some website but this ain't working.

Do you know how to do this by any chance? Is that a bug?

The command I try to bind is the following :

document.getElementById('nav_search_input');

This, on app.asana.com.

Thanks for your help!

sharat87 commented 10 years ago

You're not focusing the element. You're only selecting it. Try the following code:

document.getElementById('nav_search_input').focus();
rdewolff commented 10 years ago

Am not even focusing the element because the following code doesn't work :

alert(document.getElementById('q')); // try on Google home page - error. Debug?
// alert(document.getElementById('nav_search_input')); // try on http://app.asana.com - error.
// document.getElementById('nav_search_input').focus(); // this aint gonna work either...

So even catching the element on some page doesnt work. Try on Google Home page with the Query textinput or on app.asana.com like am trying to do. Goal is to focus quickly to the search input area on the left as the shortcuts are not editable and they are optimized for US keyboards.

Please reopen, this is not fixed.

sharat87 commented 10 years ago

Keyboard-fu's shortcuts won't work on Google search page. Google hijacks keys in a way keyboard-fu cannot detect any keypresses.

But you're right, the code doesn't work on non-google websites too (I tried reddit). I think it is because of a change in the way content-scripts are run in extensions. Please use the following code instead:

$('#nav_search_input').focus();

This use jQuery to select the element instead of DOM APIs. Unfortunately I currently lack the time to bring keyboard-fu up to what it deserves to be, so I won't be able to address this problem soon.

Nonetheless, I'm keeping this issue open so it doesn't slip my mind.