title: Setting cookie for different domain from javascript
body: <p>I am trying to set cookie to domain same as src of js file.</p>
  
  <p>Scenario:
  In <strong>www.xyz.com</strong> html, I have included js file from qwe.com as below</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="application/javascript" src="http://qwe.com/b.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>From this b.js, i want to create cookie with domain set to .qwe.com. I am setting cookie with following function</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function createCookie(name, value, days) {
      if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
      } else {
        var expires = "";
      }
      document.cookie = name+"="+value+expires+";domain=.qwe.com"+"; path=/;";
    }</code></pre>
  </div>
  </div>
  </p>
  
  <p>With above code I am unable to set cookie. 
  Example: www.flipkart.com-> Check cookies in resources tab of developer console-> .scorecardresearch.com and .doubleclick.net are able to set cookie</p>
  
  <p>I want to do same. Can someone please share solution for this? Real working solution. I have tried multiple solutions by doing Google search. It didn't work.</p>