-2

I have some code to make a table row clickable which works as it should.

The only problem is it opens the URL in the same tab. Is there a way I can change this to open the URL in a new tab?

<tr class='clickable-row' data-href='http://www.google.com'>

<script>
jQuery(document).ready(function($) {
    $(".clickable-row").click(function() {
        window.location = $(this).data("href"));
    });
});
</script>
Designer
  • 477
  • 2
  • 12
  • Try this: http://tutsplanet.com/open-url-new-tab-using-javascript/ – Arthur S. Jul 09 '19 at 20:10
  • The sum it up; nope "Nothing an author can do can choose to open in a new tab instead of a new window; it is a user preference." there are working arounds but please read similar questions to your already pointed in the comments. – Hasan Patel Jul 09 '19 at 20:20

1 Answers1

3

Try adding the 2 lines to disable default opening in same tab. You can also try to put it in a function and call the function. The function will be more useful and efficient.

<tr class='clickable-row' data-href='http://www.google.com'>

<script>
jQuery(document).ready(function($) {
    $(".clickable-row").click(function() {
       var url = $(this).attr('href');
       window.open(url, '_blank');
    });
});
</script>
Airn5475
  • 2,452
  • 29
  • 51