0

这引用了这个问题:Javascript SDK connect() function not working in chrome

我询问了有关如何使用本地存储解决的更多信息,并被要求创建一个新主题。

答案是“一种解决方法是不使用 window.opener,而是将 oauth 令牌推送到 LocalStorage 或 SessionStorage 并让 opener 窗口监听 Storage 事件。”

但我不知道该怎么做。看起来很简单,但我不知道从哪里开始。我找不到相关的例子。

4

1 回答 1

0

You can attach an event listener to the "storage" event which is fired by the window.

window.addEventListener("storage", myHandler, false);

The handler is passed an event object which includes the key which changed.

function myHandler(event) {
   if (event.key === 'the_oauth_token') {
       // do something with it
   }
}

Here's a demo: http://html5demos.com/storage-events

于 2012-06-01T21:18:22.950 回答