CR.ready

From Market Ruler Help
Revision as of 23:02, 14 November 2018 by Admin (talk | contribs) (Created page with "<code>__CR.ready</code> is a function which takes two parameters: # a function with signature <code>function (context) { ... }</code> # an optional <code>context</code> param...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

__CR.ready is a function which takes two parameters:

  1. a function with signature function (context) { ... }
  2. an optional context parameter which is passed as the first parameter

Example usage:

<script>
__CR.ready(function (cr) {
  if (document.getElementById('message-sent')) {
    cr.track("newsletter", null, cr.data("email"));
  }
}, __CR);
</script>

The function passed in may be executed after the DOMContentLoaded event in a browser, often called the DOM Ready event. If the DOM Ready has already occurred in the current browser window, the passed in function is called immediately (but asynchronously).

The value for this in the passed-in function is typically set to the browser global object window.

This function should be used when you wish to access aspects of the Document Object Model in the browser, but are not certain when your code is running and you wish to ensure it runs after the DOM is loaded. It is equivalent to the jQuery Ready function, but does not require jQuery.

Any function passed into __CR.ready is guaranteed to be executed once and only once.

This function is only available as of September 12, 2018.

See also