Rich-text Reply

JS in variant doesnt work!

MrAtiF 10-13-16

JS in variant doesnt work!

I am trying to add a popup modal that is triggered by javascript but everytime I add the code in a html module and save, the code disappears after i reopen the module. But the change is still indicated in the Variation Code editor. However, the preview does not work. How is the best way I can add the following code in?
optimizely.gif
Level 1

robertchan 10-13-16
 

Re: JS in variant doesnt work!

I can't precisely see your code, but it looks like what you're attempting to paste should be placed directly into the Variation Code as opposed to the HTML. Two other issues I can imagine you might be encountering would include timing (there's no check on whether elements exist when you fire your script), and how the HTML for the modal itself is being created.

To potentially make things easier for you, I'd recommend you have a look at this article: https://blog.optimizely.com/2013/09/12/how-to-add-a-lightbox-to-an-experiment/

The code for the modal is already there so you'd just need to style it accordingly.
Robert Chan