I have a html file that utilizes javascript to load multiple files to a page, displaying the names with a anchor tag to view each uploaded file. When I click the link, it opens in the same window. I need it to open in a new tab. Target="_blank" is not working. I suspect there is a conflict between the html and associated javascript that is creating each link. Can't figure it out after a day of research. Thank you.
{% extends "main/base.html" %}
{% block title %}
Title
{% endblock %}
{% block content %}
<button type="button" class="btn btn-primary js-upload-files">
<span class="glyphicon glyphicon-cloud-upload"></span> Upload Files
</button>
<input id="fileupload" type="file" name="file" multiple
style="display: none;"
data-url="{%url 'basic_upload' %}"
data-form-data='{"csrfmiddlewaretoken": "{{csrf_token}}"}'>
<table id="gallery" class="table table-bordered">
<thead>
<tr>
<th>File</th>
</tr>
</thead>
<tbody>
{% for file in files %}
<tr>
<td class="table_link"><a href="{{file.file.url }}" target="_blank">{{ file.file.name }}</a></td> <!-- does not open in a new tab. stays in same window -->
</tr>
{% endfor %}
</tbody>
</table>
<p><a href="/" target="_blank">click here to open a new window</a></p> <!-- test to confirm that outside of table, a link will open in a new tab -->
{% endblock content%}
/* AND MY JS */
$(function () {
/* 1. OPEN THE FILE EXPLORER WINDOW */
$(".js-upload-files").click(function () {
$("#fileupload").click();
});
/* 2. INITIALIZE THE FILE UPLOAD COMPONENT */
$("#fileupload").fileupload({
dataType: 'json',
done: function (e, data) { /* 3. PROCESS THE RESPONSE FROM THE SERVER */
if (data.result.is_valid) {
$("#gallery tbody").prepend(
"<tr><td><a href='" + data.result.url + "'>" + data.result.name + "</a></td></tr>"
)
}
}
});
});