Rich-text Reply

Works in Editor but not in Preview

hv 12-14-15
Accepted Solution

Works in Editor but not in Preview

 

Hi!

 

I got the right result shown in the Editor, while in Preview-Mode no changes are visible. Anybody can give me a hint?

 

Code in Variation #1:

 

defer(function () {
  
    $("button.primary").css({"height":"48px", "font-size":"18px", "font-weight":"600"});
    $(".icon-plus").remove();
    
});

 

With this function in the Experiment Javascript:

 

 

function defer(method) {
if (window.jQuery)
method();
else
setTimeout(function() { defer(method); }, 50);
}

 

hv
Level 2

robertchan 12-14-15
 

Re: Works in Editor but not in Preview

Set a longer time out (e.g. 2000 or above). Paste your code into the console, and see if it runs there without Optimizely, if it doesn't run then there's an issue with your code. If you have multiple experiments running on the same page, you might be previewing a different experiment. Try forcing the variant you're attempting to preview as follows:

http://YOURURL/?optimizely_xYOUREXPERIMENTID=YOURVARIANTNUMBERSTARTINGONANINDEXOF0

Robert Chan

hv 12-15-15
 

Re: Works in Editor but not in Preview

Thanks.

 

But the problem seems to lie elsewhere.... If I paste the defer-Functions code into the variation, it works. If its in the Experiment JavaScript, it doesnt. ?!

hv
Level 2
hv 12-15-15
 

Re: Works in Editor but not in Preview

Generally functions defined in the Experiment Javascript and called from variation code don't seem to fire. A simple alert placed in the Experiment Javascript gets processed though.

 

Anybody experienced this?

hv
Level 2
hv 12-15-15
 

Re: Works in Editor but not in Preview

Defined in the format
window.defer = function(method)
it works. Problem solved.

Still I would wonder why?
hv
Level 2

Re: Works in Editor but not in Preview

[ Edited ]

Hi @hv,

 

Project JavaScript, Experiment JavaScript, and variation code are each executed at different points in the stack, so they each have their own namespace and are scoped only to that namespace.  If you want access to functions and variables across these areas, appending 

window.

to each declaration will work.

Harrison Krat
Solutions Architect | Optimizely, Inc.
harrison@optimizely.com
 
hv 12-15-15
 

Re: Works in Editor but not in Preview

that's it. thank you
hv
Level 2