Warning / back to fullscreen #1364
-
Hello everyone, I have added a fullscreen mode to my experiment to minimise distractions. Is there any way of giving a warning saying something like "please don't exit fullscreen mode. And then two buttons "Withdraw" and "back to fullscreen". I already have a link to a debriefing page at the end of the experiment: jsPsych.init({ Best wishes, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hi Ina! The These Discussion posts should give you some ideas about how exactly to set this up: #1257, #1284. And feel free to follow up here if you need further guidance. |
Beta Was this translation helpful? Give feedback.
-
EDIT: I tried this and it doesn't work. See this comment. Hi @InaQuadt, sorry for the delay in responding! This may not be useful anymore but I'll follow up in case it's helpful for others. on_interaction_data_update: function(data){
if(data.event == 'fullscreenexit'){
jsPsych.pauseExperiment();
jsPsych.getDisplayElement().innerHTML = "Please enter fullscreen to continue.";
}
if(data.event == 'fullscreenenter'){
jsPsych.resumeExperiment();
jsPsych.getDisplayElement().innerHTML = "";
}
} I haven't tried this. Does it work? |
Beta Was this translation helpful? Give feedback.
-
Hi @InaQuadt and @juliameehan! It turns out that my earlier suggestion in this thread doesn't work - sorry. I think that pausing/resuming the experiment and changing the display might work between trials, but if someone exits fullscreen, that will almost certainly happen during a trial. So we can't just replace the contents of the page, because that will interfere with the current trial. Instead, we can hide the contents of the current trial, and add our own message about re-entering fullscreen. Then, once the person re-enters fullscreen, we can look to see if the 'please enter fullscreen' message is on the page, and if so, then remove it and show the trial content again. Another issue is that the Finally, I added a global variable called Here's my full solution: var should_be_in_fullscreen = false;
var fullscreen = {
type: 'fullscreen',
fullscreen_mode: true,
on_start: function() {
should_be_in_fullscreen = true; // once this trial starts, the participant should be in fullscreen
}
};
var trial = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus')
};
var trial_procedure = {
timeline: [trial],
timeline_variables: [
{stimulus: 'Hello!'},
{stimulus: 'This'},
{stimulus: 'is'},
{stimulus: 'a'},
{stimulus: 'task.'}
]
};
var fullscreen_exit = {
type: 'fullscreen',
fullscreen_mode: false,
on_start: function() {
should_be_in_fullscreen = false; // once this trial starts, the participant is no longer required to stay in fullscreen
}
};
var done = {
type: 'html-keyboard-response',
stimulus: 'Done!'
};
jsPsych.init({
timeline: [fullscreen, trial_procedure, fullscreen_exit, done],
on_interaction_data_update: function(data){
if(data.event == 'fullscreenexit' && should_be_in_fullscreen){
console.log('exited fullscreen');
// hide the contents of the current trial
jsPsych.getDisplayElement().style.visibility = 'hidden';
// add a div that contains a message and button to re-enter fullscreen
jsPsych.getDisplayElement().insertAdjacentHTML('beforebegin',
'<div id="message-div" style="margin: auto; width: 100%; text-align: center;">'+
'<p>Please remain in fullscreen mode during the task.</p>'+
'<p>When you click the button below, you will enter fullscreen mode.</p>'+
'<button id="jspsych-fullscreen-btn" class="jspsych-btn">Continue</button></div>');
// call the request fullscreen function when the button is clicked
document.querySelector('#jspsych-fullscreen-btn').addEventListener('click', function() {
var element = document.documentElement;
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
});
}
if(data.event == 'fullscreenenter'){
console.log('entered fullscreen');
// when entering fullscreen, check to see if the participant is re-entering fullscreen,
// i.e. the 'please enter fullscreen' message is on the page
var msg_div = document.querySelector('#message-div');
if (msg_div !== null) {
// remove the message
msg_div.remove();
// show the contents of the current trial again
jsPsych.getDisplayElement().style.visibility = 'visible';
}
}
},
on_finish: function () {
jsPsych.data.displayData();
}
}); |
Beta Was this translation helpful? Give feedback.
Hi @InaQuadt and @juliameehan! It turns out that my earlier suggestion in this thread doesn't work - sorry. I think that pausing/resuming the experiment and changing the display might work between trials, but if someone exits fullscreen, that will almost certainly happen during a trial. So we can't just replace the contents of the page, because that will interfere with the current trial. Instead, we can hide the contents of the current trial, and add our own message about re-entering fullscreen. Then, once the person re-enters fullscreen, we can look to see if the 'please enter fullscreen' message is on the page, and if so, then remove it and show the trial content again.
Another issue is…