Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda