Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!