Συζητήσεις » Αιτήματα Δημιουργίας

Can I prevent websites from taking focus to an arbitrary field (or other element) on page load?

§
Δημοσιεύτηκε: 25/05/2017

Can I prevent websites from taking focus to an arbitrary field (or other element) on page load?

This can be frustrating especially if the page loads slowly and the website takes to focus to a different field mid typing. It also prevent me from using single key hotkeys (/.- and such)
There's no point in taking focus into search fields and such, I can decide when I want to search.

woxxomΣυντονιστής
§
Δημοσιεύτηκε: 25/05/2017

Not tested:

// ==UserScript==
// @name        Disable autofocus while loading
// @include     *
// @run-at      document-start
// ==/UserScript==

document.addEventListener('focusin', blur, true);
window.addEventListener('load', function _() {
  window.removeEventListener('load', _);
  document.removeEventListener('focusin', blur, true);
});

function blur(e) {
  if (e.target.localName == 'input' || e.target.localName == 'textarea') {
    e.target.blur();
  }
}

If it doesn't work try removing both , true.

§
Δημοσιεύτηκε: 25/05/2017

Thanks again!

§
Δημοσιεύτηκε: 02/06/2017

Hmmm. This has some issues.
I can't even select field manually while loading it seems.
Also, it doesn't seem effective for google advanced search: https://www.google.com/advanced_search?hl=en

On this website it often fails, when I refresh: https://www.arukereso.hu/mobiltelefon-c3277/

§
Δημοσιεύτηκε: 02/06/2017

Firefox offers a "browser.autofocus" setting in about:config. Is there a reason this setting is not sufficient?

§
Δημοσιεύτηκε: 02/06/2017
Επεξεργάστηκε: 02/06/2017
Firefox offers a "browser.autofocus" setting in about:config. Is there a reason this setting is not sufficient?

I tried it. It doesn't seem to affect what happens within the page.

Δημοσίευση απάντησης

Συνδεθείτε για να δημοσιεύσετε μια απάντηση.

长期地址
遇到问题?请前往 GitHub 提 Issues。