Skip to content

Commit

Permalink
Sync session storage between tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleeckx committed Feb 17, 2017
1 parent 9c85447 commit 1b83602
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/vidyano.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
<script> Polymer = { lazyRegister: "max", useNativeCSSProperties: true, suppressTemplateNotifications: true, suppressBindingNotifications: true }; </script>
<script>
var sessionStorage_transfer = function (event) {
if (!event) event = window.event;
if (!event.newValue) return;
if (event.key == "vi-getSessionStorage") {
localStorage.setItem("vi-sessionStorage", JSON.stringify(sessionStorage));
localStorage.removeItem("vi-sessionStorage");
} else if (event.key == "vi-sessionStorage" && !sessionStorage.length) {
var data = JSON.parse(event.newValue);
for (var key in data)
sessionStorage.setItem(key, data[key]);
}
};

if (window.addEventListener)
window.addEventListener("storage", sessionStorage_transfer, false);
else
window.attachEvent("onstorage", sessionStorage_transfer);

if (!sessionStorage.length) {
localStorage.setItem("vi-getSessionStorage", "-");
localStorage.removeItem("vi-getSessionStorage");
};
</script>
<link rel="import" href="Libs/polymer/polymer.html" />
<link rel="import" href="Libs/layout/layout.html" />
<link rel="import" href="vidyano-lite.html" />
Expand Down

0 comments on commit 1b83602

Please sign in to comment.