SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have enabled attachment in my custom webpart like below.

<xsl:element name="SharePoint:AttachmentsField">
      <xsl:attribute name="runat">server</xsl:attribute>
      <xsl:attribute name="ListId">
             {} </xsl:attribute>
      <xsl:attribute name="FieldName">Attachments</xsl:attribute>
      <xsl:attribute name="ControlMode">Display</xsl:attribute>
      <xsl:attribute name="Visible">true</xsl:attribute>
      <xsl:attribute name="ItemId">
          <xsl:value-of select="@ID"/>

How can I add target="blank"?

share|improve this question

I've used jQuery in the past to find the link and add the attribute


make sure to narrow it down to your items, otherwise all links will open in new windows


share|improve this answer
hm... nice tips.Tha bUT It seems i would have to add an id to itself. How did you get to your selector? – naijacoder Jan 23 '12 at 7:30
simplest way is to wrap you items with a div tag, and give that an ID, like $("#myDiv a").attr, or give each of your hyperlinks a unique class, and that can be used like $("a.yourClass").attr – David Lozzi Jan 23 '12 at 13:13
David how do i add the class though: An element css class or ID doesn't exist by default. How did you go with yours.Please elaborate. This is my output below. <tr id="{0052E8DD-52C3-4C5B-9052-9C4D69210C0E}"> <td class="ms-vb"> <span dir="ltr"> <a href="/sites/Intranet/Comm/Lists/Co/Attachments/1/indicator.gif" onclick="DispDocItemExWithServerRedirect(this, event, 'FALSE', 'FALSE', 'FALSE', '', '1', '');return false;" onmousedown="return VerifyHref(this, event, '1', null, '');return false;" tabindex="1">indicator.gif</a> </span>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr> – naijacoder Jan 27 '12 at 4:11
I have actually managed to add the target="blank" but when i click it it doesn't open in a new window – naijacoder Jan 27 '12 at 4:57
Does it open in a new tab? And it should be target="_blank" – David Lozzi Jan 27 '12 at 12:20

Use the following js function.

$(document).ready(function() {
    $.each($("a[onclick*='DispDocItemExWithServerRedirect']"), function(i, anchor) {
       var attUrl =  $(this).attr("href");
       $(this).click(function (){; return false;});
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.