johnculviner/jquery.fileDownload — pull request #61 by arrowgamer (2014-06-06 07:08:06+00:00)
Title: Added support for working for working with cookies set on a subdomain

I used this plugin on my project, but I was required to serve files from my API which sits on an alternate subdomain than the site itself.

> **Example:**
> Site on http://www.example.com downloads a file on http://download.example.com

Setting the domain property of the cookie on the API allowed this plugin to work.

> **Example:**
> (Set Cookie: fileDownload=true; Path=/; Domain=example.com)

However, the cookie would not get cleared and so subsequent downloads would fire the success event immediately.

My alterations allow you to set the domain where cookies are expected to be cleared. It can be used as follows:

```javascript
$.fileDownload(requestUrl, {
// The domain to clear cookies from
cookieDomain: "example.com"
})
```

My project resides on different domains as we have different environments for development, stage, production. In such a scenario you may want to use the following:

```javascript
$.fileDownload(requestUrl, {
// The domain to clear cookies from
// Below will equate to the base domain (e.g. example.com, not www.example.com)
cookieDomain: window.location.hostname.split(".").slice(-2).join(".")
})
```