Drag-and-drop attachment links from file download control to Operating System to download

function(node, index, arr) {
dojo.attr(node, "draggable", "true");
dojo.attr(node, "ondragstart", "event.dataTransfer.setData('DownloadURL', 'application/octet-stream:" + node.innerText + ":" + node.href + "')");
<xp:this.loaded><![CDATA[${javascript:context.getUserAgent().isChrome() && @Attachments() != 0}]]></xp:this.loaded>

This script block modifies the download links in file download control so that if the user drags-n-drops them on the OS then they are downloaded at that location. This similar functionality is provided by Google in Gmail attachments.


Just copy this script block and paste in your XPage which has file download control (xp:fileDownload). No modifications are required to be done in file download control.

How does it work:

All the links in file download control have class name set to "xspLinkFileDownload". So the code loops through all the elements with that class name and adds the attributes of "draggable" & "ondragstart" which allow the link to be dragged and dropped in OS.


This code snippet works only in Google Chrome. I have set script block to be rendered only if the browser is Google Chrome.

Naveen Maurya
October 29, 2012 8:02 AM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

No comments yetLogin first to comment...