Google search in current site

General discussion about Custom Buttons, including feature requests.

Google search in current site

Postby jedikalimero » Thu Jan 12, 2012 8:23 pm

Do you remember in Google Toolbar one of the search buttons performed a Google search in the current site instead of all internet?

I want to make a button that performs such a a search using the contents of the firefox standard search box and the base url of the current navigation tab.

Something like:
Code: Select all
/*CODE*/

loadURI("http://www.google.com/search?q=site:" + escape(document.getElementById("addressbar").value) + " " + escape(document.getElementById("searchbar").value));


Except document.getElementById("addressbar").value is not correct and it should be only the base of the URL, not the full URL (As an example, if your current URL is "http://custombuttons.sourceforge.net/forum/posting.php?mode=post&f=2", the base URL would be "custombuttons.sourceforge.net")
jedikalimero
 
Posts: 1
Joined: Thu Jan 12, 2012 8:15 pm

Re: Google search in current site

Postby morat » Fri Jan 13, 2012 6:49 am

Try this:

Code: Select all
/*Code*/
var searchWords = BrowserSearch.searchBar.value;
var searchDomain = content.document.domain;
if (searchWords && searchDomain) {
  var query = escape(searchWords + " site:" + searchDomain).replace(/%20/g, "+");
  var url = "http://www.google.com/search?q=" + query;
  gBrowser.selectedTab = gBrowser.addTab(url);
}
morat
 
Posts: 1003
Joined: Wed Dec 28, 2011 2:38 pm

Re: Google search in current site

Postby LouCypher » Fri Jan 13, 2012 1:08 pm

LouCypher
 
Posts: 122
Joined: Fri Dec 23, 2011 7:56 pm
Location: Jakarta, Indonesia (UTC+7)

Re: Google search in current site

Postby BobbyW » Sun May 22, 2016 3:18 am

LouCypher wrote: 
Image Google Site Search

 

The above link is dead.....this is the button:

Google Site Search
BobbyW
 
Posts: 272
Joined: Sat Dec 31, 2011 6:03 am

Re: Google search in current site

Postby srazzano » Sun May 22, 2016 5:24 am

FWIW, the escape() function was deprecated in JavaScript version 1.5. Use encodeURI() or encodeURIComponent() instead.
srazzano
 
Posts: 1581
Joined: Sat Mar 31, 2012 6:42 pm
Location: Las Vegas, Nevada


Return to General Discussion