Modifying Search to Add a Send Link By Email link
My customer wanted a "send link by email" next to each search result item. "Easy", I thought and went ahead to edit the xslt for the search results. But I found out a problem with links that had spaces in them - the link in outlook would appear broken. To solve this, I had to write some simple javascript, and the process is described below.
Problem:
If you want a mailto link (href="mailto") that has in the body a link to a file, you may get a link like this:
href="mailto:body=http://server/site/library/this is my file.doc"
This is a problem, because the file name contains spaces. The email will open with a broken link in it's body:
Solution:
Luckily, SharePoint has a javascript functions that solves that for us. They are "escapeProperly" and "navigateMailToLink". What I did is create a function of my own in the page:
function SendEmailWithLink(link)
{
var link = "mailto:?body=" + escapeProperly(link);
navigateMailToLink(link);
return false;
}
And my link is:
href="#nowhere" onclick="javascript:SendEmailWithLink('
This article would'nt be complete if I didn't explain why I did this - this if for the search results xslt - the idea was to add a "send link by email" button next to each search result. The solution - change the xslt to include the script above, and a button like this:
<a title="E-mail a Link" href="#nowhere">
<xsl:attribute name="onclick">
javascript:SendEmailWithLink('<xsl:value-of select="$url"></xsl:value-of>');
</xsl:attribute>
<img border="0" src="/_layouts/images/ICMSG.GIF"/>
</a>
We also added other actions (I will try to get them published) and came up with the following for each result item:
