Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

javascript - Add a legal notice to a website made of separate pages

The website <https://www.abeille-cyclotourisme.fr/> is made by hand. Not with Wordpress or any PHP-type database.

Upon creation of this website over 15 years ago, we did not bother to add a legal notice. Now we do. We want to add to the footer of each webpage a link to a legal notice. This legal notice could be, for example, written on a webpage located in the root directory (say: the page "legalnotice.html").

I would like to use the existing footers of all webpages, without changing them, at all.

What available resource do I have there ?

The footer of each webpage contains a mail link, written as follows when placed on a page located at root:

<quote>
  <!-- Infobas  -->
  <div class="infobas">
    <table summary="Bottom footer" width="100%" cellspacing="0" cellpadding="0" border="0">
      <tbody>
        <tr>
          <td class="bas">
            <script type="text/javascript" src="scripts/contactez_nous.txt">
</script><br>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <!-- / Infobas -->
  <unquote>

In a first level sub-directory, in order to point to the "scripts" root directory, it looks as follows (note the "../" added):

<quote>  
    <!-- Infobas  -->
  <div class="infobas">
    <table summary="Bottom footer" width="100%" cellspacing="0" cellpadding="0" border="0">
      <tbody>
        <tr>
          <td class="bas">
            <script type="text/javascript" src="../scripts/contactez_nous.txt">
</script><br>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <!-- / Infobas -->
  <unquote>

The script is a text file located in the script folder located at root. It is written as follows (with hidden portions for confidentiality):

<quote>  
  /* "Contactez nous"
    Crée un message comportant l'adresse mail de l'abeille
    et un texte dans le champ objet
*/

// D&eacute;finition d'une variable contenant le d&eacute;but du code HTML

var liencontact="<a href='mailto:";

/* Ajout des diff&eacute;rents &eacute;l&eacute;ments de l'adresse mail
   dans la variable
*/
liencontact +="xxx";
liencontact +="@";
liencontact +="yyy.fr";
liencontact +="?subject=%5BAbeille%5D%20Demande%20d%27information'>";

// Affichage de la variable et du texte "contactez-nous"
document.write(liencontact+"Contactez-nous @</a>");

<unquote>

This script, with its variations for all sub-directory levels in the structure, exists in each and every page of the website. That is the beauty of it. It just works.


I would like to write and upload the page legalnotice.html and modify the script; but do not want to modify all the footers of all website pages (to adjust the link to the legalnotice.html page depending on sub-directory hierarchy) in order to make that to happen.

I know how to place a relative link to the legal notice page, but that solution would force me to modify each and every footer on the website.

I know also how to place an absolute link to the legal notice webpage, that would be better, but would not resist to changes of the website address.

Is there any way to do what I want and (1) not be forced to modify the footers of the entire website and (2) be website-address independent ?

TIA for any suggestions.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Chris G had it right. Thanks Chris. My congratulations to you. I did not believe the answer I received so I dug more.

Yes, Chris, I mean the confidential information that you uncovered ;-) I positively hate robots and just mean to hide this address from their prying clutches.

There is a bug in your suggestion (I think), in that it kills the link to the mailer. Editing this slight bug is easy. Then, as a true unbeliever, I first replaced the /legalnotice.html by https://www.abeille-cyclotourisme.fr/legalnotice.html

The code is below

/* "Contactez nous"
    Crée un message comportant l'adresse mail de l'abeille
    et un texte dans le champ objet
*/

// D&eacute;finition d'une variable contenant le d&eacute;but du code HTML

var liencontact="<a href='mailto:";

/* Ajout des diff&eacute;rents &eacute;l&eacute;ments de l'adresse mail
   dans la variable
*/
liencontact +="abeille-cyclotourisme";
liencontact +="@";
liencontact +="abeille-cyclotourisme.fr";
liencontact +="?subject=%5BAbeille%5D%20Demande%20d%27information'>";

// Affichage de la variable et du texte "contactez-nous"
document.write("<a href='https://www.abeille-cyclotourisme.fr/legalnotice.html'>Fiche juridique</a> - "+liencontact+"Contactez-nous @</a>");

This code works allright, but in contains the website address, which is not what I want. Also, it is *not what Chris G has suggested. Then I tried (since Chris G suggested it):

/* "Contactez nous"
    Crée un message comportant l'adresse mail de l'abeille
    et un texte dans le champ objet
*/

// D&eacute;finition d'une variable contenant le d&eacute;but du code HTML

var liencontact="<a href='mailto:";

/* Ajout des diff&eacute;rents &eacute;l&eacute;ments de l'adresse mail
   dans la variable
*/
liencontact +="abeille-cyclotourisme";
liencontact +="@";
liencontact +="abeille-cyclotourisme.fr";
liencontact +="?subject=%5BAbeille%5D%20Demande%20d%27information'>";

// Affichage de la variable et du texte "contactez-nous"
document.write("<a href='/legalnotice.html'>Fiche juridique</a> - "+liencontact+"Contactez-nous @</a>");

That script does not work locally. The address /legalnotice.html does not go anywhere, locally. However, when uploaded on the server, it works like a miracle. The server is Dreamhost's Debian Linux server. Is that the reason it works on the server while it does not work locally ? TIA

Anyway, thanks Chris G. Your advice is a perfect solution to my question. It works !!! I just don't know why it works :-(


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...