The SharePoint Engie that could…

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

How to make MOSS 2007 search results open in new window

with 20 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

20 Responses

Subscribe to comments with RSS.

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

    Antony Henry

    November 23, 2007 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

    March 20, 2008 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

    April 9, 2008 at 11:54 pm

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

    Dawn

    August 28, 2008 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

    October 29, 2008 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

    November 2, 2008 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

    December 8, 2008 at 12:56 am

  8. This is the XML tag

    PrashanthSpark

    December 8, 2008 at 12:56 am

  9. To Dawn: It should be _blank, as in target=”_blank”

    Bob

    February 18, 2009 at 8:05 am

  10. harb45 test test544343

    uxjahd

    May 13, 2009 at 3:03 pm

  11. yugygu6756 tyu hffdrtd y guyg ug

    hvjpjh

    May 13, 2009 at 3:55 pm

  12. gfg5454 hghj

    z6bp4h

    June 8, 2009 at 9:23 pm

  13. hjhggg6642 test test

    lqyyx0

    June 8, 2009 at 9:47 pm

  14. ghhhh5432 gfhg ghfgffff

    8rj612

    June 10, 2009 at 1:18 pm

  15. yyy8980yy ttttt rrrrr

    9yfoix

    June 12, 2009 at 6:04 am

  16. hhhk56567 fghff gffgfgggg

    kbqwnp

    June 12, 2009 at 6:21 am

  17. jjjjj67566 fgfgf sdssess er rtd

    f8l6r1

    June 12, 2009 at 7:12 am

  18. I admit, I have not been on this webpage in a long time… however it was another joy to see It is such an important topic and ignored by so many, even
    professionals. I thank you to help making people more aware of possible issues.
    Great stuff as usual….

  19. This is great for regular search results page. Do you have a solution for a search scope such as ‘This Site’ where the results are returned on the page:
    http://…/_layouts/OSSSearchResults.aspx

    Thanks much!

    Jim Heidecker

    September 17, 2009 at 8:51 pm


Leave a Reply