Setting cookies using WL.Client.setCookie

MFP 7.0 introduced a new API, WL.Client.setCookie(), that allows us to set cookies that should be sent to hosts by subsequent AJAX calls.

Documentation is lacking, so here is an example that works:

WL.Client.setCookie({
  name: 'cookieName',
  value: 'cookieValue',
  domain: 'google.com',
  path: '/', // all paths
  expires: 0 // never expires
}).then(function() {
  // callbacks go here
});

Note that unlike native APIs, no further steps are required to ensure this cookie works with HTTPS hosts – this is enabled by default.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s