Open .txt file as tooltip

2

I want to add a HELP to my code, in case he clicks the word he opens a pop-up showing the details of the fields. But I would like to do this with a .txt file ... Where to open a popup containing .txt text ! I did this in tooltip that opens a small balloon containing some information:

<style> .tooltip {
  display: inline;
  position: relative;
}
.tooltip:hover:after {
  padding: 5px 15px;
  width: 220px;
  border-radius: 5px;
  background: #333;
  background: rgba(0, 0, 0, .8);
  content: attr(data-title);
  position: absolute;
  left: 20%;
  bottom: 26px;
  z-index: 98;
  color: #fff;
}
.tooltip:hover:before {
  border: solid;
  border-color: #333 transparent;
  border-width: 6px 6px 0px 6px;
  content: "";
  position: absolute;
  left: 50%;
  bottom: 20px;
  z-index: 99;
}
</style>
<tr>
  <td align="right">
    <font face="arial" color="blue" size="-1">Senha do Usuário :</font>
  </td>
  <td>
    <input type="text" align="left" name="tx_senh_usua" size="7" value="SEDS" readonly="true">
    <span style="color: blue;" data-title="Senha padrão para novos usuários." class="tooltip">?</span>
  </td>
</tr>

Can you call a .txt file when selecting or clicking in the same way?

    
asked by anonymous 05.12.2014 / 13:59

2 answers

2

Good to read a file .txt requires a language backend (it runs on the server side). Below an example would be using PHP which is the easiest and fastest way:

<?php
    $txt = file_get_contents("arquivo.txt");
?>
<span style="color: blue;" data-title="<?php echo $txt ?>" class="tooltip">?</span>
    
05.12.2014 / 14:16
1

To open a file you have to do server side, PHP in your case.

To open the file you can use fopen () and to read line by line you can use the fgets () .

$ficheiro = fopen("inputfile.txt", "r");
$texto = array();
if ($ficheiro) {
    while (($linha = fgets($ficheiro)) !== false) {
        // aqui pode trabalhar com o conteúdo da linha
        // no exemplo crio uma array com o conteudo da linha
        $chave_valor = explode("~>", $linha);
        $texto[$chave_valor[0]] = $chave_valor[1];
    }
} else {
    // caso dê erro
} 
fclose($ficheiro);

// e agora pode exportar esse conteudo para o JavaScript
echo json_encode($texto);
    
10.12.2014 / 16:38