I am using jQuery and got several rows in a table located in a separate HTML file. Each row is redirecting to a local HTML file successfully when clicked on. (using window.location)
What I am trying to achieve
What I would like to accomplish instead is when I click the row the local HTML file is opening in a new tab and not the current one.
I am aware this would be considered easy to achieve if this was an <a>
anchor.
My problem
window.open
does not work in this specific case (at least the way I tried it) and applying target="_blank"
would be useless as this is not an <a>
tag. It's a table row.
What I've tried
jQuery:
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.open = $(this).data("href");
});
});
Seperate HTML file:
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>thead1</th>
<th>thead2</th>
<th>thead3</th>
<th>thead4</th>
<th>thead5</th>
<th>thead6</th>
</tr>
</thead>
<tbody>
<tr class="clickable-row" data-href="\path\index.html">
<td>tcell1</td>
<td>tcell2</td>
<td>tcell3</td>
<td>tcell4</td>
<td>tcell5</td>
<td>tcell6</td>
</tr>
<tr class="clickable-row" data-href="\path\differentindex.html">
<td>tcell1</td>
<td>tcell2</td>
<td>tcell3</td>
<td>tcell4</td>
<td>tcell5</td>
<td>tcell6</td>
</tr>
</tbody>
</table>
</div>
To get an overview of my DOM structure I am referring to the separate HTML file with an includeHTML function.
Sources I've read
I'm assuming I cannot use window.open
the way I've tried after reading up on how the object works.
And I've read the difference between .open and .location here. However, I am not quite sure when to use what.