How to open a new page when clicking on the table row?

1

I created a page that displays database data in a table, generated through the dataTables (Jquery) plugin. It works as follows: when the user clicks on the table row, it is redirected to an edit page.

The line of code that does this redirect is:

$("#tabela-estacoes td").click(function() {
    window.location = "editar-estacoes-trabalho.php?id=" + $(this).parent("tr").attr('identifier');
});

My question is this: how do I do to instead of redirect the page, open that data in a new tab?

    
asked by anonymous 20.07.2016 / 00:38

3 answers

0

Try to do this:

$("#tabela-estacoes td").click(function() {
    var identifier = $(this).parent("tr").attr('identifier');
    var $form = $("<form></form>");
    $form.attr({
        action: "http://endereco/editar-estacoes-trabalho.php",
        target: 'blank'
    });

    $form.append('<input type="hidden" name="id" value="'+identifier+'">');

    $('body').append($form);
    $form.submit().remove();
});
    
20.07.2016 / 02:30
2

I do it this way:

  <button onclick="myFunction()">Abrir em outra aba</button>

  <script>
  function myFunction() {
    window.open('http://www.terra.com.br', '_newtab');
  }
  </script>
    
20.07.2016 / 03:26
0

I'm not very good with Javascript but I usually use the following

<td onclick="location.href='$linkQueVcQuerCarregar'">CONTEUDO DA CELULAR</td>

It usually works as requested, but I would still do a DRY function to not get ugly, like that

$("#tabela-estacoes td").click(function() { window.open("editar-estacoes-trabalho.php?id=" + $(this).parent("tr").attr('identifier');", '_blank'); });

so it would look nice and would already be applied to all <td> of the #tabela-estacoes table; I hope I have helped.

    
20.07.2016 / 00:51