Web Actions Behind the Scenes

For the curious, explanation of the JavaScript and jQuery code used behind the scenes

Generated JavaScript / jQuery

This table shows the JavaScript code that gets generated for each Web Action.

ActionjQuery / JavaScript Equivalent
Hide
 $('#something').hide(); 

Or, if the action is provided for 'when the page first loads' option:

 $('<script></script>').text("#something { display:none; }").appendTo('head'); 
Show
 $('#something').show(); 

Or, if the action is provided for 'when the page first loads' option:

 $('<script></script>').text("#something { display:inline; }").appendTo('head'); 
Swap Images
 $('img[src*="old-image.jpg"]').attr('src', "new-image.jpg"); 
Redirect To
 window.location.replace("my-other-page.htm"); 
Remove
 $('#something').remove(); 
Insert HTML From
 $('#some-target').load("new-content.htm"); 
Insert Script From
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = "my-script-url"; $('head').append(s);
Insert Script Code(whatever script you provide)

Web Actions and document.ready()

At the end of the day, Web Actions simply get a decision ('a' or 'b' or whatever) from your agent and then generate some JavaScript code in response to which choice is selected.

  • Actions that you provide for one of your agent's choices ('a' or 'b', etc) are wrapped in $document.ready() so that they don't run until the DOM is ready to be manipulated.

  • Actions that you provide for 'when the page first loads' aren't wrapped in $document.ready().

// This part will always be present for all visitors
$('<script></script>').text("#something { display:none; }").appendTo('head');

// This part will be present for 'b' visitors
$(document).ready(function() {
	$('#something').show();
});