I want to attach a custom javascript function to the out of the box “Download a copy” ribbon button. This is to provide analytics for file downloads done through the ribbon button.
I tried this code, but it doesn’t seem to work:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script>
_spBodyOnLoadFunctionNames.push("Trackdownloads");
function Trackdownloads(){
debugger;
$("a[id='Ribbon.Documents.Copies.Download-Large']").live( "click",
function() {
alert('hello');
}
);
}
</script>
Any idea how to get this to work?
Found a solution to my problem.
Actually, attaching a javascript function to the button is not the right way to implement this.
The correct implementation is to replace the OOTB button with a custom button, and call a custom javascript function to carry out the desired action.
http://msdn.microsoft.com/en-us/library/ff407619.aspx