如何在 Firefox 上禁用 .focus()

eri*_*old 6 firefox

我正在使用最新版本的 Firefox,我想禁用 .focus() 函数对网站的使用,有什么办法可以做到这一点?

art*_*ung 1

一个 Greasemonkey 脚本旨在允许您为 Google 禁用此功能。

其源代码在这里:

// ==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","");
Run Code Online (Sandbox Code Playgroud)

现在,您可以将执行此操作的站点添加为该==UserScript==部分中的附加 @match 行,但不能保证它会起作用。但如果设置了焦点事件onload,那么它就会。但它可能会影响其他网站的行为。

  • 我写了那个用户脚本。首先,我想完全禁用 .focus() 工作,尽管问题通常发生在 onload 上,但我经常无法覆盖 onload 事件,因为它不仅仅使用 focus(),而且 [如果 onload 事件侦听器是匿名添加的,那么我无法删除它](http://stackoverflow.com/questions/3106605/removing-an-anonymous-event-listener)。 (3认同)