Firefox - Any way to prevent onload focus of form fields?

Solution 1:

You can use the NoScript plugin which is kinda like killing ants with a sledgehammer, or you can try this greasemonkey script:

// ==UserScript==
// @name           Stop Google Stealing Focus
// @namespace      http://googlesystem.blogspot.com
// @include        http://www.google.*/
// @include        http://www.google.*/ig*
// ==/UserScript==

(function () {
    document.body.setAttribute('onload',''); 
})();

That works for me – who knows if it has any other side effects though?

Solution 2:

The add-on VimFX (which allows you to control your browser with the keyboard) has an option that prevents text fields from autofocusing, which works for me on all sites I tested so far.

Since VimFX makes some drastic changes to your interface, it might be a bit of an overkill (unless you are using it anyway) or interfere with other add-ons. You can probably disable all its other features, but I haven’t tested this. If anybody is interested in turning this into a stand-alone plugin, here is the relevant patch that introduced this feature.

Solution 3:

I do not know of anything specific, but as greasemonkey scripts run as soon as the DOM is populated but before the onload event handlers are called (as stated in http://greasemonkey.mozdev.org/authoring.html) you could write a script that disabled, or changed, the onload event for the sites you want the behaviour removed from.

You would have to do this on a per-site basis though, as some sites will do more than just refocus during the onload event and you probably want the other behaviour to run.

This also won't work for sites that do the refocus directly while the page is rendering (by calling the focus method directly in a <SCRIPT> block instead of in code called by the onload event.

It might be worth searching http://userscripts.org/ to see if there are any existing scripts there for the sites you want to change the behaviour of.