-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
208 lines (172 loc) · 6.6 KB
/
index.html
File metadata and controls
208 lines (172 loc) · 6.6 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html lang="en">
<head data-version="0.0.1">
<title>Study Browser Check</title>
<link rel="stylesheet" type="text/css" href="style/structure.css"/>
<!-- FontAwesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<!--/ FontAwesome -->
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body tabindex="0">
<div class="content-wrapper">
<div id="checks" class="overlay open">
<section>
<h1>Checking browser compatibility</h1>
<article>
<p>The study uses some advanced features of JavaScript which are only supported by fairly modern browsers. Before you begin the study, we need to check whether your browser is able to run it.</p>
<p>Below, you should see a series of short tests being run. This process should only take a few seconds.</p>
</article>
</section>
<div id="test">
<h3>Testing iFrame support</h3>
<iframe src="" style="display: none">
Your browser will not be able to run this study.
</iframe>
</div>
<div id="outcome">
<p class="reason">Check failed: <em class="reason">JavaScript enabled</em></p>
<p class="close">Please return the study if you are using Prolific and close your browser. Alternatively, you may try to do the study in another browser or on another device.</p>
</div>
</div>
</div>
<script type="text/javascript">
"use strict";
/*
The browser check will ensure participants are able to complete the study on their chosen device, or recommend that they use a different one.
The search part of the URL for this page will include a study=[path relative to root] for the study URL. The consent page, navigated to if the check is successful, will use this to point the participant to the correct target study.
*/
// Test area
var lastTestOkay = true;
var testTitle = document.querySelector("#test > h3");
var testFrame = document.querySelector("#test > iframe");
// Timeout (ms) and current test index
var timeout = 1000;
var timeStep = 50;
var t = 0;
// Test urls and descriptions
// All tests resolve a paragraph containing 'Okay' in the body.
var tests = [
{
test: "browserTests/iFrame.html",
message: "iFrame support"
},
{
test: "browserTests/es6.html",
message: "JavaScript ES6 support"
},
{
test: "browserTests/modules.html",
message: "JavaScript module loading support"
}
];
var test = {
test: "browserTests/iFrame.html",
message: "iFrames enabled"
};
/**
* Catch the message from the iframe and interpret it
*/
window.addEventListener('message', function(event) {
if(event.data === "Okay")
lastTestOkay = true;
});
/**
* Periodically check whether the check has passed or the timeout period has expired
*/
function checkOkay(timer) {
if(lastTestOkay)
nextTest();
else
if(timer > timeout)
fail();
else
setTimeout(checkOkay, timeStep, timer + timeStep);
}
/**
* Run the next test or finish the checks.
*/
function nextTest() {
if(!tests.length) {
finish();
return;
}
lastTestOkay = false;
test = tests.shift();
testTitle.innerText = test.message;
testFrame.src = test.test;
setTimeout(checkOkay, timeStep, timeStep);
}
/**
* Set a failure message and stop.
*/
function fail() {
document.getElementById("outcome").classList.remove("cloak");
testFrame.remove();
document.querySelector("#outcome em.reason").innerText = test.message;
}
/**
* Forward to the consent page if required, or directly to the experiment if consent is already obtained.
*/
function finish() {
function getQueryStringValue(key) {
let regex = new RegExp("[?&]?" + key + "=([^&]+)", "i");
let test = regex.exec(window.location.search);
if(test)
return test[1];
return null;
}
// Check there's somewhere sensible to go!
if(!getQueryStringValue("study")) {
testTitle.innerText = "Checking target study";
test.message = "No study declared.";
fail();
return;
}
// Sanitation of Prolific ID
var prolificId =
getQueryStringValue("PROLIFIC_PID") || "NoIdSupplied";
// Redirect if we don't have consent for participation
var consent = getQueryStringValue("consent");
if(!consent) {
// simulate redirect (no history)
var redirectURL = window.location.href;
if(redirectURL.indexOf("index.html?") !== -1) {
redirectURL = redirectURL.replace("index.html?", "consent.html?");
} else {
redirectURL = redirectURL.replace("/?", "/consent.html?");
}
window.location.replace(redirectURL);
} else {
var redirectURL = getQueryStringValue("study") + "/";
var page = getQueryStringValue("v");
if(page)
redirectURL += page;
// remove study and page from search string
var search = window.location.search.split("&");
var newSearch = "";
for(var i = 0; i < search.length; i++) {
var s = search[i];
if(s.indexOf("study=") === -1 &&
(!page || s.indexOf("=" + page) === -1))
newSearch += (i? "&" : "") + s;
}
// Get the correct start to the querystring
if(newSearch[0] !== "?")
newSearch = "?" +
(newSearch[0] === "&"?
newSearch.substr(1) : newSearch);
redirectURL += newSearch;
var re = new RegExp("\\/(?:index\\.html)?(\\?[\\w\\W]*)");
var url = window.location.href.replace(
re.exec(window.location.href)[1], redirectURL);
window.location.replace(url);
}
}
// Hide the JS must be enabled message
document.getElementById("outcome").classList.add("cloak");
// Run the first check
checkOkay(0);
</script>
</body>
</html>