filamentgroup/jQuery-File-Download — Issue #1: Download breaks comet/websocket connection
Author: jlanglade
Created: 2012-01-06 12:19:12+00:00
State: open

Hi,

I have an application which maintain a connection to a server (using the atmosphere framework).
As soon as I download a file, the connection is aborted.

I have come to a simple solution: Use an iframe with the form inside. It's a little bit intrusive than the initial version as the iframe must be kept, but at least, it works.

Here is my code :
```javascript
$.download = function(url, data, method) {
//url and data options required
if ( url && data ) {
//data can be string of parameters or array/object
data = typeof data == "string" ? data : $.param(data);
//split params into form inputs
var inputs = "";
$.each(data.split("&"), function() {
var pair = this.split("=");
inputs += "";
});
//send request
var myIFrameforDownload = $("#frmDownload"),
myIFrameForDownloadDocument = null;
if (myIFrameforDownload.length === 0) {
myIFrameforDownload = $("").appendTo("body");
}
$("

" + inputs + "

")
.appendTo(myIFrameforDownload.contents().find("body")).submit().remove();
};
};
```