Change Search Center URL using JavaScript in SharePoint Online/2013/2016

SharePoint 2013 change search center url using jsom
SharePoint deveopment training course

This SharePoint tutorial, we will discuss how to change the search center URL in SharePoint Online/2013/2016 using JavaScript object model code (jsom).

To change the search center URL using browser we can navigate to Open SharePoint Online Site Settings -> then click on “Search Settings” which is under “Site Collection Administration”.

By default it will be blank like below:

Change Search Center URL using JavaScript in SharePoint

Change Search Center URL using JavaScript in SharePoint

Now we will see how to change the search center URL in SharePoint 2013 using JSOM (JavaScript Object Model).

Here let us take a button and on click of that button, we will change the search center URL. Both the HTML and JSOM code we have written inside a script editor web part which is inside a web part page.

We can set the SRCH_ENH_FTR_URL_SITE property which will change the search center URL.

<input type="button" id="btnSubmit" value="Set Search URL" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function () {
bindButtonClick();
});

function bindButtonClick() {
$("#btnSubmit").on("click", function () {
setSearchURL();
});
}

function setSearchURL() {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_site().get_rootWeb();
var props = web.get_allProperties();
props.set_item("SRCH_ENH_FTR_URL_SITE", "/sites/Bhawana/MySearchCenter");
web.update();
ctx.load(web);
ctx.executeQueryAsync(function () {
alert("Search Settings Modified");
},

function () {
alert("failed");
});
}
</script>

Once you Save the code and click on the button, the search center URL will be changed like below:

change search center url using javascript sharepoint

You may like following SharePoint search tutorials:

This SharePoint tutorial, we learned how to change the search center URL in SharePoint 2013/2016/Online using the JavaScript object model (jsom).

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →