How can I ensure a cookie can be read from a new window in IE?
<p>I am currently using javascript and trying to pass a sessionGUID via a cookie to a newly opened window using IE9. I wish to avoid putting the sessionGUID on the querystring.  </p>

<p>I am using the following code to open the new window and assign the cookie to the new window:</p>

<pre><code>var pathname = /msgViewer.htm?A=" + aGUID + "&amp;Detached=yes"; 
var myWindow = window.open(pathname, "detached_window");
myWindow.document.cookie = "SG=" + sGUID;
</code></pre>

<p>However, the cookie doesn't appear to be set when (document).ready executes in the new window.</p>

<pre><code>$(document).ready(function () {
...
sGUID = getCookie("SG");
...
[call to AJAX webservice that requires sGUID be passed]

...

    function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else {
        begin += 2;
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
            end = dc.length;
        }
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
</code></pre>

<p>When I set a (test) alert after the getCookie call the sGUID is undefined, however the delay (user entry) caused by the alert allows the cookie to be read after that.</p>

<p>How can I ensure the cookie is set in the new window before $(document).ready executes?  ...or at least ensure the webservice isn't called before the sessionGUID is retrieved from the cookie?</p>

<p>The issue doesn't exist in FireFox or Chrome- just IE.</p>

<p>Thanks in advance, for your consideration...</p>

<p>UPDATE (20121115):
This link <a href="http://codeigniter.com/forums/viewthread/220241/" rel="nofollow">http://codeigniter.com/forums/viewthread/220241/</a> indicates cookie data may not be available until after a page request has been made. The scenario described above generally only occurs during the initial login or after cookies have been deleted (and still intermittent at that) My current solution/workaround is to open and close a temp window and re-retrieve the cookie.  Since the issue happens when a new window is opening anyway, the additional window flicker is inconspicuous.  I also moved the retrieval of the cookie outside the $(document).ready function.
Here is the additional code:</p>

<pre><code>sGUID = getCookie("SG");
if (sGUID == null) {
    var jwURL = "/Test.htm";
    jw = window.open(jwURL, "junk_window",width=1,height=1);
    jw.close();
    sGUID = getCookie("SG");
}
</code></pre>
