The Art of SharePoint Evolution

Stories from a SharePoint Engineer that isn’t afraid of Visual Studio.

How to make MOSS 2007 search results open in new window

with 8 comments

I was searching around for information on how I could enhance my SharePoint search results and came across this blog with some tips. The tip about opening links in new windows instead of the same window was a great idea but I couldn’t use the same tips since it was for SPS 2003. I wanted to be able to open links in new windows since I noticed a lot of users often times were searching for say PDF’s and then they would accidentally close the browser instead of hitting the back button. Big annoyance for them.

So I was snooping around the Search Core Results Web Part’s XSL Editor to see if I could edit the XSL to open links in new windows instead. It’s actually pretty easy, here are the steps:

1. Go to http://portal/searchcenter/pages/results.aspx

2. Modify Shared Web Part for the Search Core Results WebPart

3. Click on the XSL Editor Button

4. I’d suggest copying the contents of the pop up into notepad/wordpad to do your editing.

5. Search for the following lines:

<span class=”srch-Icon”>
<a href=”{$url}” id=”{concat(’CSR_IMG_’,$id)}” title=”{$url}”>

______________________________________________

<span class=”srch-Title”>
<a href=”{$url}” id=”{concat(’CSR_’,$id)}” title=”{$url}”>

____________________________________________________

<xsl:choose>
<xsl:when test=”$IsThisListScope = ‘True’ and contentclass[. = 'STS_ListItem_PictureLibrary'] and picturethumbnailurl[. != '']“>
<div style=”padding-top: 2px; padding-bottom: 2px;”>
<a href=”{$url}” id=”{concat(’CSR_P’,$id)}” title=”{title}”>

__________________________________________

<span class=”srch-URL”>
<a href=”{$url}” id=”{concat(’CSR_U_’,$id)}” title=”{$url}” dir=”ltr”>

____________________________________________

6. At the ends of each of the <a href= > tags, you’ll want to add on target=”_blank”

For example to make the link attached to the document icon open in a new window, the full tag would be like this:

<span class=”srch-Icon”>
<a href=”{$url}” id=”{concat(’CSR_IMG_’,$id)}” title=”{$url}” target=”_blank”>

Using the same XSL Editor you can also manipulate how your search results are displayed and even include custom content types if you wanted to!

Written by Henry

October 27, 2007 at 2:17 pm

8 Responses to 'How to make MOSS 2007 search results open in new window'

Subscribe to comments with RSS or TrackBack to 'How to make MOSS 2007 search results open in new window'.

  1. Good one….useful tip….I’m wondering why this didn’t strike me in the first place

    Antony Henry

    23 Nov 07 at 2:08 am

  2. This a nice article. But my requirement is, clicking on the document link in Search Result page should open documents in respective application instead of Browser Window. So that user can edit the doc and save it to document source. Just like what is happened in Document library.

    Please help me.

    Thanks

    Biswajit

    20 Mar 08 at 2:43 am

  3. Hey Biswajit, did you find a solution for your problem? I’m trying to do the same, but can’t find a way.

    Thomas

    9 Apr 08 at 11:54 pm

  4. I can’t get this to work. I’ve tried both “_target” & “_new” in all four locations.

    Dawn

    28 Aug 08 at 9:20 am

  5. Hi,

    I tried putting in target =”_new” and it is not working, we cannot touch the 12 hive directory and need to do this setting at a XSLT level, please help

    sharada

    29 Oct 08 at 1:26 pm

  6. For those having difficulties - haven’t tested this but sometimes the blog styling will use fancy quotes and when you copy/paste, it doesn’t convert to the proper basic quote/unicode character. Try taking out the quotes and typing them back in manually. :)

    Henry

    2 Nov 08 at 1:21 pm

  7. I want to change CSR_IMG_ icon for folder instead of displaying IE image…

    any one has tried this idea!

    public void PreRender_Handler(object sender, System.EventArgs e)
    {
    CoreResultsWebPart coreResults = (CoreResultsWebPart)sender;
    string s = “(.*?)“;
    string repl=”$0$1“;
    Regex ex=new Regex(s,RegexOptions.Multiline|RegexOptions.IgnoreCase|RegexOptions.RightToLeft);
    string searchResultsTxt = ((Literal)(coreResults.Controls[0])).Text;
    string replaced= ex.Replace(searchResultsTxt, repl);
    ((Literal)(coreResults.Controls[0])).Text = replaced;
    }

    PrashanthSpark

    8 Dec 08 at 12:56 am

  8. This is the XML tag

    PrashanthSpark

    8 Dec 08 at 12:56 am

Leave a Reply