# Clicking an attachment link works only once

**URL:** https://meta.discourse.org/t/clicking-an-attachment-link-works-only-once/24927
**Category:** Bug
**Created:** [February 6, 2015, 9:49pm UTC](https://meta.discourse.org/t/clicking-an-attachment-link-works-only-once/24927 "2015-02-06T21:49:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [February 6, 2015, 9:49pm UTC](https://meta.discourse.org/t/clicking-an-attachment-link-works-only-once/24927/1 "2015-02-06T21:49:03Z")

</div>

**Steps to reproduce:**

- Go to [Can I upload attachments? - #2 by codinghorror - discourse - Discourse Demo](http://try.discourse.org/t/can-i-upload-attachments/123/2)
- Click on the download link for _mysqld.log_ and download the file
- Click on the same download link again

**Expected behavior:**  
Each click on the download link should start a download.

**Actual behavior:**  
Only the first click starts a download. All subsequent click do nothing. After reloading the page the first click works again.

**Notes:**  
I’ve seen this behavior in Chrome 40 on Windows. In IE11 it seems to work as expected.  
When you’re logged in this bug occurs for each download link. As visitor it affects only the first download link that you click.

This is possibly related to  
[https://meta.discourse.org/t/when-external-links-set-to-open-in-new-tab-link-cannot-be-clicked-twice/21015](https://meta.discourse.org/t/when-external-links-set-to-open-in-new-tab-link-cannot-be-clicked-twice/21015)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 6, 2015, 9:55pm UTC](https://meta.discourse.org/t/clicking-an-attachment-link-works-only-once/24927/2 "2015-02-06T21:55:32Z")

</div>

Possibly a bug for you to look at @zogstrip.

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [February 6, 2015, 11:15pm UTC](https://meta.discourse.org/t/clicking-an-attachment-link-works-only-once/24927/3 "2015-02-06T23:15:45Z")

</div>

For some reason, on subsequent clicks `window.getSelection()` includes an empty range which trips up the check in the [TopicView](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/views/topic.js.es6#L50). (Tested on Chrome 40.0.2214.93 m / Win8.1)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [February 9, 2015, 4:50pm UTC](https://meta.discourse.org/t/clicking-an-attachment-link-works-only-once/24927/4 "2015-02-09T16:50:38Z")

</div>

This should fix the issue 🐈

[https://github.com/discourse/discourse/commit/b809e02c6c43b92f618e9532b4c08e30f20fe4f8](https://github.com/discourse/discourse/commit/b809e02c6c43b92f618e9532b4c08e30f20fe4f8)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [February 9, 2015, 5:11pm UTC](https://meta.discourse.org/t/clicking-an-attachment-link-works-only-once/24927/5 "2015-02-09T17:11:26Z")

</div>


