-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_initial_browser_tests.html
139 lines (113 loc) · 5.6 KB
/
3_initial_browser_tests.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Browser test</title>
<script src = "./extra_functions/jquery-3.4.1.js" type="text/javascript"></script>
<script src="jatos.js"></script>
</head>
<body>
<div align="center" style="display: flex; flex-direction: column; margin: auto; flex: 1 1 100%; width: 90%; height: 90%;">
<div id="error_msg" style="font-family: 'Open Sans', 'Arial', sans-serif; font-size: 150%; line-height: 1.2em;"></div>
</div>
</body>
<script>
jatos.onLoad(function() {
// Make JATOS remember that this session was run
jatos.studySessionData.latestFinishedComponentId = jatos.componentId;
jatos.studySessionData.latestFinishedComponentPos = jatos.componentPos;
jatos.studySessionData.latestFinishedComponentTitle = jatos.componentProperties.title;
jatos.studySessionData.outputData.browser_device_test_results = {
curr_browser: [],
device_type: [],
test_status: [],
fail_reason: [],
err_msg: [],
}
var curr_browser = getBrowser();
// record browser status in jatos
jatos.studySessionData.outputData.browser_device_test_results.curr_browser = curr_browser;
var device_type = userAgentDetect();
jatos.studySessionData.outputData.browser_device_test_results.device_type = device_type
/* If this is IE - checks the document mode, to verify it's 10 or later, otherwise displays an error message */
var docMode = document.documentMode;
if (device_type=='smartphone' || device_type=='tablet') {
$("#error_msg").html("<p><br><br><br>It looks like you're using a mobile device. This study cannot be done on a mobile phone or tablet.<br><br>Please mark the experiment as incomplete.</p>");
jatos.studySessionData.outputData.browser_device_test_results.test_status = "fail";
jatos.studySessionData.outputData.browser_device_test_results.fail_reason = "MOBILE";
var err_msg = 'MOBILE';
jatos.studySessionData.outputData.browser_device_test_results.err_msg = err_msg;
if ("prolific_ID" in jatos.studySessionData) {
err_msg = err_msg + '_' + jatos.studySessionData.prolific_ID;
}
jatos.submitResultData(JSON.stringify(jatos.studySessionData), function() {return jatos.endStudyAjax(false,err_msg);});
} else if (curr_browser=='IE' && docMode < 10) {
$("#error_msg").html("<p><br><br><br>It looks like you're using an old version of IE. This study can only be run on IE 10 and up.<br><br>Please mark the experiment as incomplete.</p>");
jatos.studySessionData.outputData.browser_device_test_results.test_status = "fail";
jatos.studySessionData.outputData.browser_device_test_results.fail_reason = "old_IE";
var err_msg = 'OLD_IE';
jatos.studySessionData.outputData.browser_device_test_results.err_msg = err_msg;
if ("prolific_ID" in jatos.studySessionData) {
err_msg = err_msg + '_' + jatos.studySessionData.prolific_ID;
}
jatos.submitResultData(JSON.stringify(jatos.studySessionData), function() {return jatos.endStudyAjax(false,err_msg);});
} else {
// $("#error_msg").html("<p> You've passed the test</p>");
jatos.submitResultData(JSON.stringify(jatos.studySessionData), jatos.startNextComponent);
}
});
// ////////////////////////////////////// FUNCTIONS /////////////////////////////////////////////
function getBrowser () {
// Opera 8.0+
if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
return 'opera';
}
if (typeof InstallTrigger !== 'undefined'){
return 'firefox';
}
if(/constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification))) {
return 'safari';
}
if(/*@cc_on!@*/false || !!document.documentMode) {
var isIE = true;
return 'IE';
}
if(!isIE && !!window.StyleMedia) {
return 'edge';
}
if(!!window.chrome && !!window.chrome.webstore) {
return 'chrome';
}
} // end getBrowser
function userAgentDetect() {
if(window.navigator.userAgent.match(/Mobile/i)
|| window.navigator.userAgent.match(/iPhone/i)
|| window.navigator.userAgent.match(/iPod/i)
|| window.navigator.userAgent.match(/IEMobile/i)
|| window.navigator.userAgent.match(/Windows Phone/i)
|| window.navigator.userAgent.match(/Android/i)
|| window.navigator.userAgent.match(/BlackBerry/i)
|| window.navigator.userAgent.match(/webOS/i)) {
if (window.navigator.userAgent.match(/Tablet/i)
|| window.navigator.userAgent.match(/iPad/i)
|| window.navigator.userAgent.match(/Nexus 7/i)
|| window.navigator.userAgent.match(/Nexus 10/i)
|| window.navigator.userAgent.match(/KFAPWI/i)) {
return 'tablet';
} else {
return 'smartphone';
}
} else if (window.navigator.userAgent.match(/Intel Mac/i)) {
return 'desktop_or_laptop';
} else if (window.navigator.userAgent.match(/Nexus 7/i)
|| window.navigator.userAgent.match(/Nexus 10/i)
|| window.navigator.userAgent.match(/KFAPWI/i)) {
return 'tablet';
} else if (($(window).width() < $(window).height())) {
return 'smartphone';
} else {
return 'Unknown';
}
}
</script>
</script>