SharePoint (v3.0) Link Lists core modification for Open in New Window

Background: Often requested option by users is for a link to external page in a Link List webpart/list to open to a new browser window. SharePoint doesn’t support this action/option without some modifications.

In the simplest form this means adding code to each link html tag like “target=_blank”. This code tell the browser to open a new window when the link is clicked.

SharePoint builds the Link List url/html tag programmatically during the site’s page display so adding the noted code also requires some programmatical way*.

*Note: <shift>+click by the user also will open any link in a new window.

A Google search for “SharePoint Links open in new window” will reveal numerous postings asking about this feature, why its not available (by default), and/or every type of fix or workaround imaginable. Most offer modifications that force ALL links to open in a new window – javascript code or core hacks (not flexible). Some suggested taking the entire list webpart and converting to xml part and modifying each link via code changes (yuck!). Only one by Andrew Connell seemed to offer hope of adding it as an option for each link within the context of the link list. But I had some issues with his suggestion in that you had to create an addition calculated field to merge the URL + target=_blank along with numerous core code modifications which applied to v2.0 (older version) of SharePoint.

1) Andrew Connell (2005) Adding OpenInNewWindow option

2) Bryan Glass (2008) Change Links…open in new window

3) MSDN Create Custom List Definition

4) Sharepoint Solution Team Blog (2007) Javascript method for links to open in new window

My ‘fix’ took ideas from reference #1, #2, and #3 to make a few core code modifications that appears to provide the Open in New Window option on each link created. This is definitely a hack and I’m sure violates best practices but so far so good.

The gist of this fix basically creates a new boolean field “Open in New Window” that is tested in the code and then the Link URL will be created one of two ways depending on if its checked or not.

**Backup any core file modified so it could be restored if needed
**Backup modified files – future updates/patches may over-write your changes

Files modified (2):

C:\Program Files\Common Files\microsoft shared\web server extensions\12\TEMPLATE\FEATURES\LinksList\Links\schema.xml

C:\Program Files\Common Files\microsoft shared\web server extensions\12\TEMPLATE\FEATURES\ctypes\ctypeswss.xml

Changes In Schema.xml:

1) locate the <Fields> section (near top) add a new <Field…/> after the one for Name=”URL”. The GUID was generated and very very unlikely to conflict with another.

    …….
     <Fields>
      …….
           <Field ID="{AD22016D-BC8B-4631-A0A3-5E84C6CFA7EC}" Type="Boolean" Name="OpenInNewWindow" DisplayName="Open in New Window" Sortable="FALSE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" Required="TRUE">
          </Field>

2) Next find the first <FieldRefs> section which is actually part of the <Field Name=”URLwMenu”…> section. Add a new <FieldRef…>

<FieldRef Name="OpenInNewWindow" />

3) Next within this section but a bit further down (around line 100) find,

<Column Name="URL" HTMLEncode="TRUE" /><HTML><![CDATA[">]]></HTML>

4) Replace with:

<Column Name="URL" HTMLEncode="TRUE" />
<HTML><![CDATA["]]></HTML>
<Switch>
     <Expr><Column Name="OpenInNewWindow" /></Expr>
     <Case Value="1">
          <HTML><![CDATA[ target="_blank"]]></HTML></Case>
</Switch>
<HTML><![CDATA[>]]></HTML>

5-7) Next repeat steps 2,3,4 of the above for the next section which will be for <Field … Name=”URLNoMenu”…>

Save the changes to schema.xml

Changes In ctypeswss.xml:

1) Find <ContentType ID=”0x0105” which is for the Link type where we’ve just modified its schema.xml file.
2) Add to <FieldRefs> a matching entry for the new field we’re creating

<FieldRef ID="{AD22016D-BC8B-4631-A0A3-5E84C6CFA7EC}" Name="OpenInNewWindow" Required="TRUE" /> <!– New Window checkbox –>

3) Save ctypeswss.cml

For these changes to take affect the SharePoint site needs to be reset – accomplish this by recycling the AppPool for the site via IIS Manager.