Loading jQuery for instrumenting pages

From Market Ruler Help
Jump to: navigation, search

The __CR.jquery function takes two parameters; the first of which is a callback which has the first parameter the jQuery global (typically window.jQuery or window.$).

cr.jquery(loaded, force)

The second parameter is an optional boolean value which should be true to force the script to load a new version of jQuery from the ConversionRuler servers. You should only do this if an incompatible version of jQuery exists on the page or for compatibility reasons.

Otherwise, the current version of jQuery which is loaded is 1.11.3. It is only loaded if jQuery is not detected on the page and the 2nd parameter is not true. Detection checks for the existence of the window.jQuery variable being defined.

An example of its usage is:

<script>
window._crq = window._crq || [];
window._crq.push(function (cr) {
    cr.jquery(function ($) {
        // Do jQuery stuff here using $ as the loaded version of jQuery
    });
});
</script>

For more information, read the jQuery documentation.

Revisions

  • May 17, 2018 - Added the force parameter to __CR.jquery
  • June 6, 2016 - __CR.jquery publicly available as part of the JavaScript Functions

See also