diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-10-15 19:17:29 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-10-15 19:17:29 +0000 |
commit | 9b5c6cf86ed8dbf749bc2e401d4f87d340b6413d (patch) | |
tree | 38e035f0b797edeb5bdbc708681eacedeef53887 /html/server/ping.js | |
parent | cce112d40a6e36b2c437418e84c57490818603cb (diff) |
Fixed webhttrack incompatibility with Chrome
* closes:#53
Also fixed HTML-escaping issues inside webhttrack
Rationale: The webhttrack script made the wrong assumption that once the "browse" command returned, it meant the user killed the navigation window, and it had to kill the server itself. However, modern browsers tend to "attach" to an existing session (creating a new tab, for example, within an existing window), causing the browsing command to return immediately, thus causing the server to be killed immediately by the webhttrack script. I have rewritten the logic behind, and now the server is able to kill himself if the parent script dies, AND if the browsing client did not make any activity for two minutes. The "activity" can be any browser/refreshed page, or the internal "ping" iframe (which pings the server every 30 seconds). With this model, we *should* be compatible with old browsers, and modern ones.
Diffstat (limited to 'html/server/ping.js')
-rw-r--r-- | html/server/ping.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/html/server/ping.js b/html/server/ping.js new file mode 100644 index 0000000..c7760f7 --- /dev/null +++ b/html/server/ping.js @@ -0,0 +1,26 @@ +// Function aimed to ping the webhttrack server regularly to keep it alive +// If the browser window is closed, the server will eventually shutdown +function ping_server() { + var iframe = document.getElementById('pingiframe'); + if (iframe && iframe.src) { + iframe.src = iframe.src; + setTimeout(ping_server, 30000); + } +} + +// Create an invisible iframe to hold the server ping result +// Only modern browsers will support that, but old browsers are compatible +// with the legacy "wait for browser PID" mode +if (document && document.createElement && document.body + && document.body.appendChild && document.getElementById) { + var iframe = document.createElement('iframe'); + if (iframe) { + iframe.id = 'pingiframe'; + iframe.style.display = "none"; + iframe.style.visibility = "hidden"; + iframe.width = iframe.height = 0; + iframe.src = "/ping"; + document.body.appendChild(iframe); + ping_server(); + } +} |