Share via


HOW TO: Open Content Query Web Part links in a new IE window

This post is a contribution from Charls Tom Jacob, an engineer with the SharePoint Developer Support team.

Content Query Web Part is a nice way to query and display data from multiple lists.  By default, when you click on a link displayed in the Content Query Web Part, it opens up in the same IE browser window.  This can be annoying at times if users want to stay on the main page and view the items in a different IE browser window.

In this post, I’ll describe how to extend the out of the box Content Query Web Part and the styles such that links open in new IE window.

Step1: Extend out of the box XSL

  1. Download the out of the box ItemStyle.xsl from Style Library (go to Site Actions –> View all site content –> Style Library –> XSL Style Sheets).

  2. Rename the file to ItemStyleExtended.xsl.

  3. Open the file in NOTEPAD, locate the <DIV> element that acts as a container for links displayed in the web part:

    <div class=”link-item”>

  4. Modify the following anchor tag to open the links in a new window:

    <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">

    As

    <a href="{$SafeLinkUrl}" title="{@LinkToolTip}" target="_blank">

  5. Comment out the XSL that performs an additional check for links to documents or other file types, as below:

    <!--<xsl:if test="$ItemsHaveStreams = 'True'">
           <xsl:attribute name="onclick">
              <xsl:value-of select="@OnClickForWebRendering"/>
           </xsl:attribute>
         </xsl:if>
         <xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'">
            <xsl:attribute name="onclick">
               <xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/>
            </xsl:attribute>
         </xsl:if>-->

  6. Upload the new file to Style Library.

Step2: Extending the Content Query Web Part

  1. Open the Web Part page that contains the Content Query Web Part.

  2. Export the web part, save it as “Extented_Content_Query.webpart”.

  3. Open the web part file in NOTEPAD, modify the following:

    a. Set the title property to "Extended Content Query"
        <property name="Title" type="string">Extended Content Query</property>
    b. Set the XSLItemLink to the uploaded XSL style sheet file:
        <property name="ItemXslLink" type="string">/Style%20Library/XSL%20Style%20Sheets/ItemStyleExtended.xsl</property>

  4. Upload the extended Content Query Web Part to web part gallery.

  5. Add the extended Content Query Web Part to the web part page.

  6. Point the web part source to a document library in the site.

  7. Click on a link to verify that it opens in a new IE window.

Hope this helps!

Comments

  • Anonymous
    January 01, 2003
    Good solution. I was wondering if this worked with MOSS, but the changes in the ItemStyle are a little beyond me. Do you think this will work with SharePoint 2013?
  • Anonymous
    January 11, 2015
    There is no style sheet in the Style Library. Is there another place it might be located or so? Thanks
  • Anonymous
    May 17, 2017
    Thank you! This was very helpful and worked well in SP 2013. Anyone following the above steps will want to make sure to use <!-- instead of <!- to comment out the additional XSL, or you will receive an error.
    • Anonymous
      May 17, 2017
      My comment is not displaying properly... if you type two dash (-) marks, this page will only display one... hence making the "comment out" in step 5 and also in my comment, display incorrectly.