Does anyone have custom javascript code that will create a pop-up warning when participants try to switch tabs or windows?
THANKS!
Does anyone have custom javascript code that will create a pop-up warning when participants try to switch tabs or windows?
THANKS!
Hi
This is a code I did earlier for my client test, hope t can help you. The code will pop-up an alert when user switch tab and comeback. I flag the result with embedded data as warning in the 1st time and compromised in 2nd time. You can change the message as you like.
Qualtrics.SurveyEngine.addOnload(function() {
var tabSwitched = false;
window.addEventListener('blur', function() {
if (!tabSwitched) {
alert("!!! Please do not switch tabs during the test. Switching tabs again will flag your result as compromised !!!");
tabSwitched = true;
Qualtrics.SurveyEngine.setEmbeddedData('compromised', 'Warning');
} else {
alert("!!! Your result is compromised !!!");
Qualtrics.SurveyEngine.setEmbeddedData('compromised', 'Yes');
}
});
});
Hope it help
Thanks so much! I will try to implement and let you know if it works.
It did work! Thanks.
Thanks again for your help!
Here’s the modified version that do both
Qualtrics.SurveyEngine.addOnload(function () {
let tabSwitchCount = parseInt(Qualtrics.SurveyEngine.getEmbeddedData('tabSwitchCount')) || 0;
const blurHandler = function () {
tabSwitchCount++;
Qualtrics.SurveyEngine.setEmbeddedData('tabSwitchCount', tabSwitchCount);
if (tabSwitchCount === 1) {
alert("!!! Please do not switch tabs during the test. Switching tabs again will flag your result as compromised !!!");
Qualtrics.SurveyEngine.setEmbeddedData('compromised', 'Warning');
} else {
alert("!!! Your result is compromised !!!");
Qualtrics.SurveyEngine.setEmbeddedData('compromised', 'Yes');
}
};
window.addEventListener('blur', blurHandler);
Qualtrics.SurveyEngine.addOnUnload(function () {
window.removeEventListener('blur', blurHandler);
});
});
This worked perfectly. Thanks again for all your help!!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.