diff --git a/src/xdomain_cookie.html b/src/xdomain_cookie.html
index 831e686..051b6b2 100644
--- a/src/xdomain_cookie.html
+++ b/src/xdomain_cookie.html
@@ -34,14 +34,14 @@
window.addEventListener('message', function(event){
var origin = event.origin || event.originalEvent.origin; // For Chrome, the origin property is in the event.originalEvent object.
- if (origin !== _iframe_origin) return; //incoming message not from iframe page
-
+ if ( [_window_origin,_iframe_origin].indexOf(origin) === -1 ) return; //incoming message not from iframe page
+
//We must filter messages here to verify that it's the specific message/type we are looking for, and not from another script
var data = null;
try{
data = JSON.parse(event.data);
}catch(e){}
-
+
if(data && typeof data==='object' && 'msg_type' in data && data.msg_type==='xdsc_write' && 'namespace' in data && data.namespace === _namespace){
_set_local_cookie( data.cookie_name, data.cookie_val, parseInt(data.expires_days,10) );
//ping down to page again to update values of xdomain cookie data
diff --git a/src/xdomain_cookie.js b/src/xdomain_cookie.js
index 6f3f684..0537f21 100644
--- a/src/xdomain_cookie.js
+++ b/src/xdomain_cookie.js
@@ -113,6 +113,9 @@
_set_cookie_in_iframe( cookie_name, cookie_value, expires_days );
}
+ //set local cached value
+ _xdomain_cookie_data[cookie_name] = cookie_value;
+
}
//function to call after instantiation to sync a cookie, supplying a cookie name, value to write if it does NOT exist, expires
diff --git a/test/test_page.html b/test/test_page.html
index fb5da72..0f8c2f7 100644
--- a/test/test_page.html
+++ b/test/test_page.html
@@ -42,6 +42,8 @@
if(!cookie_val){
+ if(is_dev) console.log("SETTING EMPTY COOKIE", cookie_test_val);
+
xd_cookie.set( 'test_cookie', cookie_test_val, 30, xdomain_only );
//get again to verify that it was set