How to make MOSS 2007 search results open in new window

I wanted to be able to open PDF links only 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 on right under Miscellaneous > Data View Properties

XSLEditorButton

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;> 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”>

7. Now to open new window only for PDFs documents add the code <xsl:choose> in for Icon, Title and URL section code in the XSL. Oviously, the code inside the <xsl:when> and <xsl:otherwise> tag will be different.

<xsl:choose>
  
<xsl:when test="contains($url,'.pdf') or
contains($url,'.PDF')"
>
     
<a href="{$url}" id="{concat('CSR_IMG_',$id)}"
title="{$url}" target="_blank">
       
<img align="absmiddle"
src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
     
</a>
  
</xsl:when>
  
<xsl:otherwise>
      
<a href="{$url}"
id="{concat('CSR_IMG_',$id)}" title="{$url}">
        
<img align="absmiddle"
src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
      
</a>
   
</xsl:otherwise>
</xsl:choose>

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!

Tagged with:
Posted in SharePoint

SharePoint Content Query Web Part Open New Window

I have five solutions, most of which involve code. The first solution is probably the easiest for you:

First solution
These MSDN articles tell you how to modify ItemStyle.xsl and add your own CQWP style to it (http://www.microsoft.com/belux/msdn/nl/community/columns/stevenvandecraen/contentquerywebpart.mspx, http://msdn.microsoft.com/en-us/library/bb447557.aspx) You should be able to override the code which displays hyperlinks and insert target=”_blank”.

Second solution
This link to Heather Solomon is helpful also http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx

Third solution
The next suggestion is to use javascript to find all links in the Content Query Web Part and set their targets after the page has loaded. Probably an icky solution for you but possible.

Forth solution
You might use Visual Studio to create a webpart which inherits from the Content Query Web Part and writes all hyperlinks with new browser targets. See google.

Fifth solution
My last suggestion is to get something like the Enhanced Content Query Web Part and see if that will do it for you (http://www.codeplex.com/ECQWP)

Tagged with:
Posted in SharePoint

Opening Document Library PDF Items in MOSS 2007 in a New Window

In SharePoint 07 document library do not open PDF files in a new window. When I open the document, the PDF file is opened to same browser session. User often try to close the document by closing the browser and this is a problem.

I found three solutions,

First Solution : Modify client Adobe Reader setting.

Adobe Reader has an option called “Disable display of PDF in browser” that you need to change on your clients.
In Adobe Reader 9 :

1. Edit – Preferences
2. Category : Internet
3. Uncheck the “Display PDF in browser ”

But unfortunately you need to do that on every client computers.

Second Solution : Modify XSLT.

Edit the document library in SharePoint Designer.
1. Open the site in SharePoint Designer and then open the document library allitems.aspx.
2. Right-click the document library web part and select “Convert to XSLT data view”.
3. Locate the name column, you will see this tag “<A onfocus="OnLink(this)" HREF="{@FileRef}"….. ”, add “target=”_blank”” in tag.
4. After this, the documents will be opened in a new window.

But unfortunately you need to do this to all document libraries to open documents in new window.

Third Solution : Modify ONET.XML.

1. Open the folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\XML

Apparently there is now a “global” folder for site definition files, I am still trying to understand the mapping of things from SPS 2003 and MOSS 2007.

2. Find and open the file named “ONET.XML” in your favorite XML/text editor (good old notepad for me please)

3. On line 693 you will find this line of XML:

<Else><HTML><![CDATA[<A onfocus=”OnLink(this)” HREF=”]]></HTML>

Changing this line to as shown below will change the behavior of the textual links to open in a new window

<Else><HTML><![CDATA[<A onfocus=”OnLink(this)” target=”_blank” HREF=”]]></HTML>

4. On line 838 you will find this similar line of XML:

<Else><HTML><![CDATA[<A TABINDEX=-1 HREF=”]]></HTML>

Changing this line to as shown below will change the behavior of the image icon links to open in a new window

<Else><HTML><![CDATA[<A TABINDEX=-1 target=”_blank” HREF=”]]></HTML>

5. Save changes do an IISRESET and you should be good to go. Of course if you are in a medium or large farm scenario you will need to perform these steps for each front-end web server

I would recommend the third solution.

Reference

http://www.jjfblog.com/2006/12/one-issue-that-came-up-during-recent.html

http://social.technet.microsoft.com/Forums/en/sharepointadmin/thread/9db08c4a-b53c-419a-84f8-001c194d1311

http://social.technet.microsoft.com/Forums/en-US/sharepointadmin/thread/530e2ea1-d77d-491c-935f-04f536e439a5

Tagged with:
Posted in SharePoint