Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
parametric func() selection in <body onload="func()" > tag depending on argument parameter in html

I have an index.html running a menu

<a href='./satellites.html'> 
<a href='./simulation.html'>

The server responds by sending one of the two files requested and a header. The two files (satellites.html and simulation.html) are almost the same with the only difference in the function that is called when loaded

<!-- in the satellites.html-->
<body onload='init()'>            
...

and 
<!-- in the simulation.html-->
<body onload='initSimulation()'>  
...

Otherwise, the two HTML programs are identical.

Everything works fine but I want to avoid repeating the same code. How can the server control which function the client will call (using URL parameters probably)? I searched but it seems that the header is not available neither in HTML or in javascript.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Using cookies offers a solution, which I do not like because some users do not allow cookies. But nevertheless, I include it here for reference: In the index.html (the clientside menu):

<!-- in index.html-->
<body>
   ...
   <a href='./satellites.html' class='button'>
   <a onclick="return false" ondblclick="startSimulation()" class='button'>
   ...
   <script>
       function startSimulation(){
          document.cookie = "simulation=true";
          window.location.replace("./AISsatellites.html");
       }
    </script>
</body>

Now the server stores and sends always the same file. The client via the cookie decides which function to call as follows:

<!-- in satellites.html-->   
<body onload='select_Simulation_or_Online()'>
...
   <script>
      function select_Simulation_or_Online(){
         if(document.cookie.indexOf('simulation=')==0) {
            simulation = true;
            document.cookie = 'simulation=; expires=Thu, 01-Jan-1970 00:00:01 GMT;';
            initSimulation();
         }
        else {
            simulation = false;
            init();
        }
   ...
   </script>
</body>

Still looking for a solution without the use of cookies - possibly using a parameter that the server places in the header, to be read by the client.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda