0

We created several new content search web part display templates based off some existing templates from production. After getting these new templates setup with all the web parts and finished configuring them, once we started using them we discovered that our new search pages are using an # anchor tag instead of a normal ? querystring when a search was performed. The original templates are working as we expected and do use the ? querystring when performing a search.

For instance, in the new pages we are getting this retuned in the URL address:  “http://abc/search/pages/people.aspx#k=smith” instead of this: “http://abc/search/pages/people.aspx?k=smith

Our original search pages use the ? query string operand, but our new search pages use the # anchor tag. We are not sure why the # anchor tag is being used by the search query engine because that is not our intent.

Any assistance would be appreciated in helping us figuring out why the expected ? querystring is not being used.

Thank you.

Addendum: I cam across this blog which is similar but not a perfect fit for my situation, but I wanted to mention it. The difference between this blog solution and the issue I am having is that our initial query is using the # hash while in this blog example it occurs on each subsequent query, but not the initial query.  The URL is http://blogs.msmvps.com/marafa/2014/01/21/how-to-get-the-query-string-value-in-sharepoint-2013-search-results-page/ I have copied most of the body of this URL shown below:

After i developed this scenario, I found that SharePoint if you ran another search keyword for the second time, It would append the newer keyword with anchor (#) and will keep the old search keyword in the query string with key “K”

For example, When you run the search for the first time with keyword “copyright“:

http://myPortal2013/sites/sp2013/search/pages/results.aspx?k=copyright

If you changed the search keyword to “digital”, here is the new url would be:

http://myPortal2013/sites/sp2013/search/pages/results.aspx?k=copyright#digital

In my case, i want to get the “digital” and not “copyright” keyword so i want to parse the Url and get the latest search keyword. Here is the code to accomplish this:

// This will be sued to send the terms to the xxxxxxxx
var sParam = document.location.href.split(“#”)[1];
if(sParam == null)
{
sParam = window.location.search.substring(1).split(‘=’);
sParam = sParam[1];
}
else
{
// when there is not anchor (#) in the url
sParam = sParam.split(‘=’)[1];
}

This code i wrote it in the outer div element of the body of your display template html file.

Note: You can use this variable “sParam” as you like in the Display Template html file.

(Visited 46 times, 1 visits today)
Add a Comment