7
I have a table with several information, in local server. I use a jQuery to detect when I click on a line and pass this information via GET. On the same page, I treat this information with PHP isset().
PHP
if(isset($_GET["contrato"])){
    if($_GET["contrato"]!=""){
        $contrato = $_GET["contrato"];
        $nome = $_GET["nome"];
        $tel = $_GET["tel"];
        # Trabalho com as variáveis  
    } else {
        echo "Nenhum contato selecionado!";
    }
} else {
    echo "Nenhum contato selecionado!";
}
jQuery
$(document).ready(function(){
    $("tr[class=contato]").click(function(){
        document.execCommand("copy"); //copia o que estiver selecionado
        var msg = "?contrato="+$(this).children(".g0").html()+
                  "&nome="$(this).children(".g1").html()+
                  "&tel="$(this).children(".g2").html();
        window.location.href = msg;
    });
});
HTML
<table>
    <tr class="contato">
        <td class="g0">1000</td>
        <td class="g1">João</td>
        <td class="g2">DDD+numero</td>
    </tr>
    <tr class="contato">
        <td class="g0">1001</td>
        <td class="g1">Maria</td>
        <td class="g2">DDD+numero</td>
    </tr>
    <tr class="contato">
        <td class="g0">1002</td>
        <td class="g1">José</td>
        <td class="g2">DDD+numero</td>
    </tr>
</table>
The way it is, whenever you click on a table row, the command document.execCommand("copy"); will be executed even if there is nothing selected.
I wonder if there is any way to check, in javascript/jQuery, if the user selected something before running the command to copy.
$().select() only works with input or textarea see https://api.jquery.com/select/
– Anderson Henrique
So there is no way to check if any text has been selected?
– Paulo Dos Santos
@Paulodossantos was not I who gave the downvote, but I think you better explain what you want to do. I say this because it may be a XY problem and may have a better way to do what you want.
– fernandosavio
@fernandosavio I understand! But 8bit understood exactly what I wanted to say. Thank you!
– Paulo Dos Santos