How to automatically clear a query from Firefox’s Search bar

Please Note: I’ve moved home, read this article at its new address! Thank you!

About these ads

  1. I use a bit of JavaScript (along with the userchrome.js extension) to get the job done.

    userchrome.js extension: http://forums.mozillazine.org/viewtopic.php?t=397735

    Code:

    /* :::: Searchbar Autoclear :::: */
    (function()
    {
    var searchbar = BrowserSearch.getSearchBar();
    if(searchbar && “handleSearchCommand” in searchbar)
    {
    eval(“searchbar.handleSearchCommand =”+searchbar.handleSearchCommand.toString().replace(
    ‘var textValue = textBox.value;’,
    ‘var textValue = textBox.value; setTimeout(function(){ BrowserSearch.getSearchBar().value = “”; }, 1000);’
    ));
    }

    }());

  2. Thanks for the top Aaron!
    I’ve found userChrome.css to be very handy, so I think using the userchrome.js extension will give just the right result! (plus other tweaks can be added)
    Great tip!

  3. I don’t see what the big deal is. When I click anywhere in the search text box, the previously searched phrase becomes highlighted so that it is overwritten by the new item to be searched.

  4. ans

    holy christ just use ctrl+k people.

    and don’t install another bloated extension – if you want to make the search box wider type about:config in the address bar, press enter, scroll down to “browser.urlbar.hideGoButton” and change the value to true. this eliminates the little green arrow that no one uses and widens the box.

  5. @ans
    This article is not about making the search box wider, it’s about automatically clearing its content when a search is done, so please read the title!
    Also, if 30KB is considered bloated by you, you might want to try Searchbar Autosizer Lite (7KB), which you have to set using about:config (seems more like something you’d like).

  6. midorigin

    thanks for the tip. i couldn’t find an answer to this anywhere.

  7. ferrouswheel

    For those that don’t “get” this extension… learn about middle-click pasting in unix. CTRL-K or selecting the text in the search box results in the selection buffer being overwritten.

  8. nate

    I use Firefox regularly on Linux and am a big fan of middle-click pasting. That is exactly why I WANT this functionality. I often highlight something in a DIFFERENT application, click back on Firefox and find my search bar already has something in it. If I highlight it to remove it, I’ve just lost the text I wanted to copy in the first place. (Not lost because I can get it back from Klipper, but still.) Personally, I have absolutely no use for clicking the magnifying glass to search as hitting enter is much easier, so I’d prefer it if clicking that cleared the bar instead (a la clear buttons in OS X). Anybody know how to remap that button’s function, maybe through JavaScript?

  9. Michael

    Btw, the add-on “SearchLoad Options” does a perfect job!! It resets the search bar, let you define to open the search results in a new tab, can reset search engine after x seconds…

    https://addons.mozilla.org/en-US/firefox/addon/searchload-options/

  1. 1 Blog Mirrors » Firefox Tip: Automatically clear searchbar query on Enter

    [...] How to automatically clear a query from Firefox’s Search bar [The Authentic Fake] Original post by Lifehacker [...]

  2. 2 検索ボックスの文字列を自動クリアするfirefox拡張を作ってみた

    [...] 実は、肝心のこれだけのコードの書き方がなかなかわからなかった。まず、検索ボックスの検索アクションに function を bind させる方法がわからず(上記 init で eval してるところ)、次に、検索時に検索ボックスを空にすると検索エンジンに検索文字列が渡らないという現象に悩まされた(上記 onSearch で setTimeout してるところ)。 結局、いろいろ探しているうちに、userchrome.js の上で同じ事をやってる人を、こちらのブログのコメント欄で発見し、これを頼りに上記のように書いてみたら、ようやくうまくいった感じ。この辺のプロパティ名とかがオフィシャルにまとめてあるところが見付からないんだな.. どなたかご存知でしたら教えてください。 [...]




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



Follow

Get every new post delivered to your Inbox.

%d bloggers like this: