JavaScript

media2click provides a JavaScript API for easy integration with other privacy tools, i.e. the cookie banner of your choice.

JavaScript API

media2click.js exposes these methods:

media2click.setCookieLifetime(lifetime)

Parameter data type:

integer

Return data type:

void

Sets the cookie lifetime to the number of days given.

media2click.getActiveHosts()

Return data type:

array

Returns an array of all currently activated hosts.

media2click.isActiveHost(host)

Parameter data type:

string

Return data type:

boolean

Returns the current activation status of the given host.

media2click.addHost(host)

Parameter data type:

string

Return data type:

boolean

Activate the host and update the cookie. Returns true if the host identifier is valid and the host is active.

media2click.removeHost(host)

Parameter data type:

string

Return data type:

boolean

Deactivate the host and update the cookie. Returns true if the host identifier is valid and the host is inactive.

media2click.updateCookie()

Return data type:

void

Update the cookie.

media2click.activateAllForHost(host)

Parameter data type:

string

Return data type:

boolean

Immediately activate the content of all content elements attached to the given host. Returns false if the host identifier is invalid.

Best Practice

The initialization of the media2click object ist delayed until the document is in a complete ready state. If this leads to undefined variable errors, use something like this:

document.onreadystatechange = function () {
  if (document.readyState === 'complete') {
    if (typeof media2click === 'undefined') {
      var media2click = new Media2Click(TYPO3.settings.TS.m2cCookieLifetime);
    }

   /* your code here ... */
  }
};