summaryrefslogtreecommitdiff
path: root/html/server/ping.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/server/ping.js')
-rw-r--r--html/server/ping.js26
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();
+ }
+}