[9575f0]: / test.html  Maximize  Restore  History

Download this file

87 lines (77 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body onload="onBodyLoad()">
<script>
window.addEventListener("message", receiveMessage, false);
let url0, url1, activeUrl, urlSet = false, timer = -1;
function onBodyLoad() {
url0 = document.getElementById("url0");
url1 = document.getElementById("url1");
}
function receiveMessage(event) {
if (activeUrl.startsWith(event.origin)) {
if (timer !== -1) {
clearTimeout(timer);
timer = -1;
console.log("Received messages. Killing timer!");
}
var message = event.data;
console.log(message);
if (message === "--INFO--\"Still polling the registration of the visualization. Is the visu stopped?\"") {
console.log("Webvisu stopped? Switching to different url");
setTimeout(switchToDifferentWebvisu, 1000);
}
if (message === "Error while processing the visualization: Sending service aborted") {
console.log("Download? Switching to different url");
setTimeout(switchToDifferentWebvisu, 1000);
}
if (message === "--INFO--\"Triing to reconnect after error\"") {
console.log("Error? Switching to different url");
setTimeout(switchToDifferentWebvisu, 1000);
}
}
}
function setURL() {
document.getElementById('frame').src = url0.value;
url0.disabled = true;
url1.disabled = true;
document.getElementById("button").disabled = true;
activeUrl = url0.value;
urlSet = true;
}
function onLoad() {
if (urlSet) {
timer = setTimeout(function () {
console.log("No message received after 5 seconds, switching to different webvisu.");
switchToDifferentWebvisu();
}, 5000);
}
}
function switchToDifferentWebvisu() {
if (activeUrl === url0.value) {
activeUrl = url1.value;
} else if (activeUrl === url1.value) {
activeUrl = url0.value;
} else {
console.error("Unexpected settings! Abort!");
return;
}
document.getElementById('frame').src = activeUrl;
}
function onError() {
console.log("onError");
}
</script>
<iframe id="frame" onload="onLoad()" onerror="onError()"></iframe>
<br><br>
<label for="url0">Url0:</label>
<input type="text" id="url0" name="url0" value="http://localhost:8080/webvisu.htm"><br><br>
<label for="url1">Url1:</label>
<input type="text" id="url1" name="url1" value="http://localhost:8080/webvisu.htm"><br><br>
<button type="button" id="button" onclick="setURL()">Change</button>
</body>
</html>