Monday, September 22, 2008

Open list items in new window.

. Monday, September 22, 2008

Here one can have two scenarios.

1) A list with a column of type URL. Upon clicking on this URL it should open in a new window: -


Add a HIDDEN content editor webpart on the list view page (e.g. http:///lists/testlist/allitems.aspx). Add the following script in the source editor.
{script language="JavaScript"}

//add an entry to the _spBodyOnLoadFunctionNames array

//so that our function will run on the pageLoad event

_spBodyOnLoadFunctionNames.push("rewriteLinks");



function rewriteLinks() {

//create an array to store all the anchor elements in the page

var anchors = document.getElementsByTagName("a");

//loop through the array

for (var x=0; x0)
{


//store the HTML for this anchor element


oldText = anchors[x].outerHTML;


//rewrite the URL to remove our test text and add a target instead


newText = oldText.replace(/#openinnewwindow/,'" target="_blank');


//write the HTML back to the browser


anchors[x].outerHTML = newText;

}

}

}

{/script}
replace {} in script tag with <>.

Additionally you need to append the following at the end of the URLs for each item in the list.

#openinnewwindow




2) List views whose titles linked with edit menus have to be opened in a new window.

For this the list view (e.g. allitems.aspx) needs to be edited using SharePoint designer.

a) Open the listview page in split mode in SharePoint designer.
b) Select the listview webpart in design mode that displays items of the list in current view.
c) Right-click and select ‘convert to XSLT data view’.
d) Once converted, click on the one of the row titles in design mode. This will select its corresponding code in SPD.
e) Select the following line from the code. This is the line that we will modify. Replace it with below given string.
locate href="{$URL_Display}?ID={@ID}" . replace target="_self" with target="_blank"
f) Check-in and test the page.

========

got this from one other site. thanks poster


0 comments: