I'm using the latest versions of Firefox and I'd like to disable the .focus() function's use for websites, is there any way to do this?

link|improve this question

74% accept rate
Since I cannot comment here yet, I add an answer Can't you change to window.focus=function() { // whatever you want here return false; // no more focus } – mplungjan Feb 2 '11 at 6:59
feedback

2 Answers

There is a Greasemonkey script designed to allow you to disable this for Google.

The source code to that is here:

// ==UserScript==
// @name         Google Disable Auto Focus
// @namespace    googleDisableAutoFocus
// @include      /^http:\/\/(www\.)?google\.c(a|om)\/?$/i
// @include      http://www.google.tld/
// @match        http://www.google.com/
// @match        http://www.google.ca/
// @run-at       document-start
// @datecreated  2010-02-21
// @lastupdated  2010-02-21
// @version      0.1
// @author       Erik Vergobbi Vold
// @license      GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @description  This userscript will disable Google's auto focus
// ==/UserScript==

document.body.setAttribute("onload","");

Now, you could add sites that do this as additional @match lines in the ==UserScript== section, but there's no guarantee it would work. But if the focus event is set onload, then it would. It may affect other site behavior though.

link|improve this answer
I wrote that userscript. First of all, I want to disable .focus() from working altogether, albeit the issue usually happens onload but I often can't overwrite the onload event because it does more than just use focus(), and if the onload event listener is anonymously added then I cannot remove it. – erikvold Jun 27 '10 at 3:22
Hah! I didn't even notice that. Maybe onload get the identity of whatever's been focused, then blur() it. Or, I wonder if there's a way to completely alter the focus method, sort of like changing its .prototype -- though I don't know if there is such an equivalent. Lastly, maybe insert a shim object into the DOM as the last part of the onload event, focus it, then remove it from the DOM. – artlung Jun 27 '10 at 13:46
The main reason I want to disable focus() is so that I don't lose focus of what I was on. If I "insert a shim object into the DOM as the last part of the onload event, focus it, then remove it from the DOM" then I will still lose focus of what I was on I think. – erikvold Jun 27 '10 at 20:24
Erik, yeah, I see why the shim won't work in that case. :-( I'm out of ideas short of getting into the fundamental guts of Firefox. I'm wondering if the plugin api's would allow for what you are trying to do. – artlung Jun 29 '10 at 2:16
feedback

I wish I could do that for the whole of Windows, I only want windows to take focus from the app I'm working on if something very serious is going to happen to the computer - I hate apps popping up when I'm typing!

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.