Rich-text Reply

How to activate a timeout function?

miguelm 03-04-16
Accepted Solution

How to activate a timeout function?

Hi,

 

I set an experiment with the following code:

setTimeout(function(){ $('.botCheckAvailability > a').click(); }, 9000);

 

I checked in the Optimizely log and the code is running, however, the function is not executed. In activation mode is set as inmediately. I was reading the documentation and I think that I need to change the activation mode to "Conditional activation" and call the timeout function from there.. but I don't know how. :?

 

Thank you

 

 

Level 2

JDahlinANF 03-04-16
 

Re: How to activate a timeout function?

[ Edited ]

Your timeout function may be running just fine and you wouldn't know it because what you are trying to do is not something that works in JavaScript - you cannot click a link and make it take the user to the link's href.

 

See here for more info:

http://makandracards.com/makandra/17267-trigger-a-link-s-click-action-with-javascript

 

If you are trying to follow the link, this is the code you are looking for:

setTimeout(function(){ 
	$link = $('.botCheckAvailability > a');
	$link[0].click();
}, 9000);

 

miguelm 03-08-16
 

Re: How to activate a timeout function?

Hi,

 

thank you @nap0leon  also I can fix it adding the window prefix.

setTimeout(function(){ window.$('.botCheckAvailability > a').click();}, 9000);

"It turns out the Optimizely jQuery version of .click does not work for this modal. However we did discover that leveraging the window's version of jQuery does work fine. This scoping issue was resolved by scoping the variation code to the window level with the window. prefix."

Level 2