Forum Discussion

Dorje-McKinnon's avatar
Dorje-McKinnon
Iron Contributor
Jun 10, 2019

How to get Modern search results, before modern search reaches your tennant.

This post outlines how we gave our users modern search results prior to getting the modern search box in the black navigation bar. I hope it is useful to the community.

 

We went live with an upgrade to our intranet a month or so prior to the modern search box coming to our tennant's navigation bar.

 

To minimise user training we wanted to move straight to modern search results (despite their limitations regarding verticals and filters).

 

We tried

  • changing the site settings / search settings in our intranet site to point to the modern search results page e.g. /sites/OurSite/_layouts/15/search.aspx/siteall?q=
    • This didn't work
  • we kept the default search box (below navigation bar, top right of the page)
    • because the new intranet is using modern pages we couldn't add a JS redirect easily to every page
    • so we took a copy of the /search/results.aspx in case we needed it and replaced it with a new results.ASPX page that uses Javascript to read the search term and redirect it to modern search.

When you search in the default box it sends the search terms to /search/results.aspx?k=SearchTerm

Our new results.ASPX page reads the search terms using Javascript, adds them to the modern search address and redirects the user to /sites/OurSite/_layouts/15/search.aspx/siteall?q=SearchTerm

 

The code for the page is below [use at your own risk]:

If you use it remember to 

New Results.aspx code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
<meta name="description" content="New results page to redirect to modern">
<script>
var strUrl = "";
var strTerm = "";
strTerm = getQueryVariable("k");

strUrl = "https://YourTennant.sharepoint.com/sites/YourIntranet/_layouts/15/search.aspx/siteall?q=";
strUrl = strUrl + strTerm;

function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}

window.location.replace(strUrl);
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Results Search Redirect</title>
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<SharePoint:CssRegistration Name="default" runat="server"/>
</head>

<body>
We tried to redirect you to :
<script>
document.write(strUrl);
</script>
copy and paste this link into the address bar of the browser to get where you need to go.
<form id="form1" runat="server">
</form>

</body>

</html>

 

 

No RepliesBe the first to reply

Resources