Although there is currently no API in the JavaScript CSOM which lets you change the search center url directly, SharePoint stores the search settings in the Property Bag of the root SPWeb object in a site collection. You can set these property bag values and your search settings should get modified.
"SRCH_ENH_FTR_URL" – Search Center URL
"SRCH_SITE_DROPDOWN_MODE" – Search Scope Drop down option
"SRCH_TRAGET_RESULTS_PAGE” – Target Search Results page
Using JavaScript Client Object Model, you can set the values like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ctx = new SP.ClientContext.get_current(); | |
var web = ctx.get_site().get_rootWeb(); | |
var props = web.get_allProperties(); | |
//Search Center Url | |
props.set_item("SRCH_ENH_FTR_URL","/sites/search/pages"); | |
//Search Scope Drop down option | |
props.set_item("SRCH_SITE_DROPDOWN_MODE","HideScopeDD_DefaultContextual"); | |
//Target Search Results page | |
props.set_item("SRCH_TRAGET_RESULTS_PAGE","/sites/Search/Pages/results.aspx"); | |
web.update(); | |
ctx.load(web); | |
ctx.executeQueryAsync(function () { | |
alert("Search Settings Modified"); | |
}, | |
function() { | |
alert("failed"); | |
}); |
Do Not Show Scopes Dropdown, and default to contextual scope: "HideScopeDD_DefaultContextual"
Do Not Show Scopes Dropdown, and default to target results page: "HideScopeDD"
Show scopes Dropdown: "ShowDD"
Show, and default to ‘s’ URL parameter: "ShowDD_DefaultURL"
Show and default to contextual scope: "ShowDD_DefaultContextual"
Show, do not include contextual scopes: "ShowDD_NoContextual"
Show, do not include contextual scopes, and default to ‘s’ URL parameter: "ShowDD_NoContextual_DefaultURL"