Open file . txt as tooltip

Asked

Viewed 192 times

2

I’m wanting to add to my code a "HELP", type if he click the word he open a pop-up showing the details of the fields. But I would like to do this with a file .txt ... Where open a pop-up containing the text of .txt! I did it in tooltip which opens a small balloon containing 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>

You can call a file .txt when selecting or clicking the same way?

  • The content of .txt inside the tooltip? or has to be a same popup?

  • It would have to be a popup, but not like an Alert e-e' I showed an example with the tooltip, because it’s a more "flashy example".

  • 1

    You will have to read this TXT somehow, you can not do only via HTML and CSS

  • What language is using in the backend?

  • Yes @Khaosdoctor, I have in mind that I will have to use JS or some other language to read. txt, but I don’t know how to make it appear as a pop-up file. txt!

2 answers

2


Good for reading a file .txt needs a language backend(wheel on 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>
  • This really helped me @Antonyalkmim! Thank you very much!

1

To open a file you have to do on the 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);
  • $text in the case will contain what is in the contents of . txt né?

  • And to open it as Focus it changes the tooltip?

  • @Alexandre "$text in case will contain what is in the content" => yes. I will update the other answer soon to continue the idea here.

  • It’s OK @Sergio, well removed my doubt!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.