How to set Search Center URL in SharePoint Online Office 365 using JavaScript Object Model?

SharePoint 2013 change search center url using jsom

In this post, we will discuss how we can set search center URL in SharePoint Online Office 365 site collection using JavaScript object model code. The same code will also work in SharePoint 2016/2013.

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”.

SharePoint deveopment training course

By default it will be blank like below:

sharepoint online change search center url jsom
SharePoint online change search center url jsom

Set search center URL SharePoint 2013 jsom

Now we will see how to set 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.

Code:

<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, it will set the search center url like below:

SharePoint 2013 change search center url using jsom
SharePoint 2013 change search center url using jsom

You may like following SharePoint 2013 search tutorials:

Hope this will be helpful to set search center URL in SharePoint Online Office 365 using JavaScript object model (jsom) code.

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 →