Rich-text Reply
Highlighted

Timing of Modal Only Showing Once

smcurrey528 08-05-19
Accepted Solution

Timing of Modal Only Showing Once

Hi, I am currently using the lightbox extension in Optimizely, but we want the modal to only appear once per session. I tried the code below and there is some flashing of the modal before it is hidden. Is it because of the waitForElement? Optimizely recommends that as a way to fix timing issues on their help pages. https://help.optimizely.com/Troubleshoot_Problems/Fix_a_timing_issue

 

var utils = window.optimizely.get('utils');
utils.waitForElement('.lightbox_extension').then( function(modal){
var summerModal = sessionStorage.getItem('seenOnDemandModal');
  if (!summerModal){
    modal.style.display = "block";
    sessionStorage.setItem('seenOnDemandModal', 'true');
} else if (summerModal === 'true') {
		modal.style.display = "none";
	}
});
0 Likes
0 Likes
CouchPsycho 08-06-19
 

Re: Timing of Modal Only Showing Once

Hi,

if you want to prevent the flashing, set the element style to display:none by default. The flashing may result, as you have already mentioned, because of the interval waitForElement is checking the existence of the element.

Kind regards

Michael