Set cookie domain with Javascript variable
<p>Im taking the domain from the HTML of the page using jQuery:</p>

<pre><code>domainUrl = $("p.domain").text();
</code></pre>

<p>for the purposes of testing:</p>

<pre><code>&lt;p class="domain"&gt;.vl3.co.uk&lt;/p&gt;
</code></pre>

<p>Which is also the domain Im testing the script on.</p>

<p>This then give an alert containing the correct domain:</p>

<pre><code>alert(domainUrl);
</code></pre>

<p>I want to the use that variable to set the domain in a cookie:</p>

<pre><code>set_cookie('visible', 'no', 2020, 1, 1, '/', '+domainUrl+');
</code></pre>

<p>Here is the set cookie function:</p>

<pre><code>function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ) {
  var cookie_string = name + "=" + escape ( value );
  if ( exp_y ) {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path )
    cookie_string += "; path=" + escape ( path );
  if ( domain )
    cookie_string += "; domain=" + escape ( domain );
  if ( secure )
    cookie_string += "; secure";
  document.cookie = cookie_string;
}
</code></pre>

<p>Why doesnt the cookie domain get set? </p>

<p>I think the problem is how im using the domainUrl variable when setting the cookie?</p>
