How to find out which object currently has focus
KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()
KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()
A solution is to post a delayed runnable that checks to see if the EditText view is still focused, and if it is not, focus it. editText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(final View v, boolean hasFocus) { if (hasFocus) { // Request focus in a short time because the // keyboard may steal it … Read more
Try this: $.fn.focusWithoutScrolling = function(){ var x = window.scrollX, y = window.scrollY; this.focus(); window.scrollTo(x, y); return this; //chainability }; and then $(‘#link’).focusWithoutScrolling(); Edit: It’s been reported that this doesn’t work in IE10. The probable solution would be to use: var x = $(document).scrollLeft(), y = $(document).scrollTop(); but I haven’t tested it.
If you really need to do this, make the box transparent, not hidden: opacity:0; filter:alpha(opacity=0); Alternatively, if you want to ensure that the user doesn’t accidentally click it, just place the input inside a div with width: 0; overflow: hidden; However, there is most certainly a better way to do what you want, maybe using … Read more
You can add en event filter. This is an example of an application written with QtCreator. This form has a QComboBox named combobox. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWindow) { ui->setupUi(this); ui->comboBox->installEventFilter(this); . . . } bool MainWindow::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::FocusOut) { if (object == ui->comboBox) { qWarning(object->objectName().toLatin1().data()); } } return … Read more
Maybe I’m misreading the question, but wouldn’t the following do (assuming an editable <div> with id “editable”)? The timer is there because in Chrome, the native browser behaviour that selects the whole element seems to trigger after the focus event, thereby overriding the effect of the selection code unless postponed until after the focus event: … Read more
In HTML 4.01, focus is only discussed in the context of elements such as form controls and links. In HTML 5, it is discussed much more widely. However, how focus works for documents is mostly browser dependent. You might try: // Give the document focus window.focus(); // Remove focus from any focused element if (document.activeElement) … Read more
It’s a well known bug on Safari, both on iPad and iPhone. A workaround it’s to change the position to absolute to all elements set with fixed position. In case you are using Modernizr you could also target mobile devices this way: jQuery code $(document).ready(function() { if (Modernizr.touch) { $(document) .on(‘focus’, ‘input’, function(e) { $(‘body’).addClass(‘fixfixed’); … Read more
It is not possible – due to security concerns. unless by “tab” you mean a window and a popup window that (due to browser preferences) opened up in a new tab. If this is the case, then yes you can. //focus opener… from popup window.opener.focus(); //focus popup… from opener yourPopupName.focus();
My problem was the Button XML defining: android:focusableInTouchMode=”true” Remove this attribute and the button doesn’t require being touched twice. It appears as though the first touch is consumed to assign focus on the button and the second then triggers the OnClickListener. Note that the Button works without issue with the android:focusable=”true” attribute.