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.
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.