我正在用支持它的浏览器(除了IE之外的任何人)用localStorage替换cookie .问题是site.com和www.site.com存储自己独立的localStorage对象.我相信www被认为是一个子域名(如果你问我,这是一个愚蠢的决定).如果用户最初在site.com上并决定输入www.site.com在下次访问时,她的所有个人数据都将无法访问.如何让所有"子域"与主域共享相同的localStorage?
我确定这只是我的语法问题,但我正在尝试将变量发送到 iframe(供 colorbox 使用)。目前我接受两端的任何域(只是为了让它工作)。这是发送页面的js:
$(document).ready(function() {
if(window.location.hash) {
var urlimage = window.location.hash.substring(1);
targetiframe = document.getElementById('wbgallery').contentWindow;
targetiframe.postMessage(urlimage, "*");
console.log(urlimage);
}
});
Run Code Online (Sandbox Code Playgroud)
这是接收页面:
$(document).ready(function() {
window.addEventListener('message',receiveMessage);
console.log(event);
function receiveMessage(event) {
if (origin !== "*")
return;
inbound = event.data;
console.log(inbound);
}
});
Run Code Online (Sandbox Code Playgroud)
我看到了 urlimage 的控制台日志,可以看到一个事件,但没有任何入站事件。我正在使用Mozilla 的解释来尝试解决所有问题。