I use the searchbox in Firefox quite often. But dragging and dropping text on it or right-clicking and choosing search... from the context menu can get annoying, especially if you want to search more phrases from a page. And let's face it, nobody uses the F1 key for Help, so ...
To map the F1 key (or another shortcut) to automatically search selected text in Firefox, you'll have to install the keyconfig extension. After restarting Firefox, go to Tools | Keyconfig. For each of the following code snippets, add a new key, choose a name, check the global checkbox and paste the code in the code section.
// Search (using the current search engine) in background tab
var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var submission = ss.currentEngine.getSubmission(getBrowserSelection(), null);
gBrowser.loadOneTab(submission.uri.spec, null, null, submission.postData, true, false);
// Search (using the current search engine) in foreground tab
var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var submission = ss.currentEngine.getSubmission(getBrowserSelection(), null);
gBrowser.loadOneTab(submission.uri.spec, null, null, submission.postData, false, false);
// Search (using the default search engine) in background tab
var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var submission = ss.defaultEngine.getSubmission(getBrowserSelection(), null);
gBrowser.loadOneTab(submission.uri.spec, null, null, submission.postData, true, false);
// Search (using the default search engine) in foreground tab
var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
var submission = ss.defaultEngine.getSubmission(getBrowserSelection(), null);
gBrowser.loadOneTab(submission.uri.spec, null, null, submission.postData, false, false);
I found this code here. After creating these actions, you'll need to associate a keyboard shortcut to them. I chose F1, F2, Shift+F1 and Shift+F2 for them.
Restart Firefox, select some text and hit F1 or F2. It should open a new tab in the background (or in the foreground) with the results of the currently selected search engine.
Wednesday, July 30, 2008
Map a keyboard shortcut to automatically search selected text in Firefox
Subscribe to:
Post Comments (Atom)
1 comments:
Danke schön
Post a Comment