Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于2个windows的本地存储通信_Javascript_Html_Local Storage - Fatal编程技术网

Javascript 用于2个windows的本地存储通信

Javascript 用于2个windows的本地存储通信,javascript,html,local-storage,Javascript,Html,Local Storage,我创建了一个小项目,单击按钮打开一个新窗口。此窗口正在从服务器请求信息 窗口现在应该将信息传递回放置按钮的主页面 我曾尝试使用localStorage,这是我迄今为止得到的: 发件人: var fbKey = "test"; localStorage.fb_auth_key = fbKey; alert(localStorage.fb_auth_key); window.opener.postMessage("test", "http://example.com") 接收人: docum

我创建了一个小项目,单击按钮打开一个新窗口。此窗口正在从服务器请求信息

窗口现在应该将信息传递回放置按钮的主页面

我曾尝试使用localStorage,这是我迄今为止得到的:

发件人:

var fbKey = "test";

localStorage.fb_auth_key = fbKey;

alert(localStorage.fb_auth_key);
window.opener.postMessage("test", "http://example.com")
接收人:

document.getElementById('output').textContent = "" + localStorage.fb_auth_key;
接收方一直在刷新此消息,但我总是得到“未定义”-发送方中的警报具有正确的结果


谢谢您的帮助。

我想您只设置了一个局部变量属性

try:window.localStorage.getItem(“键”)
和:window.localStorage.setItem(“key”,value)

也许您可以使用跨文档消息传递:

发件人:

var fbKey = "test";

localStorage.fb_auth_key = fbKey;

alert(localStorage.fb_auth_key);
window.opener.postMessage("test", "http://example.com")
收到:

window.addEventListener("message", function(e){
        if(e.origin === "http://example.com/"){
            if(e.data){
                document.getElementById("output").textContent = e.data;
            }
        }
    }, false);