This is an old revision of the document!


By design, clicking on the add to cart button before the page is fully loaded takes you to the full page cart. If you would like to prohibit this default behavior use the following JavaScript code snippet.

The following JavaScript code will select all DOM elements on a webpage which are links and forms, used to add items to Foxy cart, and set their display property to “none” till the FC (Foxy Cart) object is ready. The FC onload event will run a function, inside of which the FC.client.on ('ready.done') event triggers a callback function that will iterate through the nodelist of selected elements and set their style property to “block”.

/*
match all a elements whose href attribute's value contains "/cart" and form elements 
whose value of the action attribute contains "/cart"
*/
var fcElements = document.querySelectorAll('a[href*="/cart"], form[action*="/cart"]');
//iterate through the nodelist and set the display property to none
for (var i = 0; i < fcElements.length; i++) {
    fcElements[i].style.display = "none";
}
var FC = FC || {};
FC.onLoad = function() {
    FC.client.on('ready.done', function() {
        for (var i = 0; i < fcElements.length; i++) {
            fcElements[i].style.display = "block"
        }
    }); //end of FC client.on
}; //end of onload

Site Tools