Fast way of opening a link in a modal dialog in SP2010

June 26th, 2012 | Categories: SharePoint 2010

A lot of times I prefer to open a link in a modal dialog instead of new window or even same window. SP.UI has a function to open a modal dialog, but a lot of times you don’t need to create that function. A lot of times I just prefer to use SharePoint’s built-in function. So to open a page in a modal dialog just change your link from

<a href="http://your-sharepoint-url-address">your link name</a>

to

<a onclick="NewItem2(event, this.href); return false;" href="http://your-sharepoint-url-address">your link name</a>

This code ofcourse works in SharePoint designer and other areas in SharePoint where you have SP.UI loaded. It also doesn’t work in rich text fields in SharePoint as the JavaScript gets filtered out.