我已经制作了一个用于在我的页面上下载文件的表格,这是我的代码:
<script>
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.location = $(this).data("href", "_blank");
});
});
</script>
目前无法在新标签页中打开。这是为了打开.pdf,所以我希望它在新标签中打开所述pdf。任何人吗?
编辑:这是html代码
<table class="tftable" border="0">
<tr><th>Filer for nedlastning</th></tr>
<tr class="clickable-row" data-href="/s/Profilmanual-april-2018.pdf"><td>Profilmanual</td><td>April 2018</td><td>3,98 MB</td><td>PDF</td>
<tr class="clickable-row" data-href="/s/Logofiler.zip"><td>Logofiler</td><td>April 2018</td><td>7,02 MB</td><td>ZIP</td>
<tr class="hide"><td>Fonter</td><td>April 2018</td><td>X MB</td><td>ZIP</td>
</table>
答案 0 :(得分:2)
在动态插入的target
标记上设置href
属性(而不是对<a>
做的任何事情):
jQuery(document).ready(function($) {
$(".clickable-row").each(function(index) {
var href = $(this).attr("data-href");
$(this).children().each(function(index) {
$(this).html('<a href="' + href + '" target="_blank">' + $(this).html() + '</a>');
});
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="tftable" border="0">
<tr><th>Filer for nedlastning</th></tr>
<tr class="clickable-row" data-href="/s/Profilmanual-april-2018.pdf"><td>Profilmanual</td><td>April 2018</td><td>3,98 MB</td><td>PDF</td>
<tr class="clickable-row" data-href="/s/Logofiler.zip"><td>Logofiler</td><td>April 2018</td><td>7,02 MB</td><td>ZIP</td>
<tr class="hide"><td>Fonter</td><td>April 2018</td><td>X MB</td><td>ZIP</td>
</table>
&#13;
或者,您可以使用window.open
功能:
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.open($(this).attr("data-href"), "_blank");
});
});
&#13;
.clickable-row:hover {
cursor: pointer;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="tftable" border="0">
<tr><th>Filer for nedlastning</th></tr>
<tr class="clickable-row" data-href="/s/Profilmanual-april-2018.pdf"><td>Profilmanual</td><td>April 2018</td><td>3,98 MB</td><td>PDF</td>
<tr class="clickable-row" data-href="/s/Logofiler.zip"><td>Logofiler</td><td>April 2018</td><td>7,02 MB</td><td>ZIP</td>
<tr class="hide"><td>Fonter</td><td>April 2018</td><td>X MB</td><td>ZIP</td>
</table>
&#13;
由于某种原因,这似乎不适用于Stack Snippet。
答案 1 :(得分:0)
尝试使用
<script>
var link = whatever ur link is;
window.open(link, '_blank');
</script>