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 or SharePoint 2013.


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

Also, you can read:
How to use Deferred when done in JavaScript Object Model in SharePoint 2013 to make asynchronous to synchronous call?

Microsoft flow Save my email attachments to a SharePoint document library Configuration

Steps to create a result source and use custom result source in a content search web part in SharePoint online

By default it will be blank like below:

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

This we can set using Jsom also.

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


Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

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 →