Javascript Help - Bug With Custom Pop-Up Messsage | Experience Community
Skip to main content

Javascript Help - Bug With Custom Pop-Up Messsage

  • March 2, 2026
  • 1 reply
  • 12 views

Forum|alt.badge.img+1

Hi, I have added the custom code found on a community post to a question in Qualtrics. The code displays a pop-up message asking participants not to leave the survey screen. The code works well when a participant clicks into the search bar or opens a new tab in the same window. However, if they leave the window (by clicking on the desktop for example), the code glitches quite heavily. Specifically, when they return to the survey screen, the pop-up message continuously pops on and off and the participant can’t interact with the survey. This happened for one test participant using Safari and another test participant using Chrome. However, a 3rd test participant using Chrome said it worked fine. Is there anyway to update the code below to avoid this bug? Thank you!

 

Qualtrics.SurveyEngine.addOnload(function() {
    // Requires 'leaveCount' Embedded Data field initialized in Survey Flow
    let count = parseInt(Qualtrics.SurveyEngine.getEmbeddedData('leaveCount')) || 0;

    window.addEventListener('blur', function() {
        count++;
        Qualtrics.SurveyEngine.setEmbeddedData('leaveCount', count);
        // Optional: Trigger alert or set warning flag
        alert("Please do not switch tabs during the reflection.")
    });
});
 

1 reply

Forum|alt.badge.img+1
  • Author
  • March 2, 2026

Sorry - I posted this question twice. Upon posting the first time, I didn’t get a success message and thought my posting had been lost.