daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  <script type="text/javascript">
  2.          // transfers sessionStorage from one tab to another
  3.          console.log("1");
  4.          var sessionStorage_transfer = function (event) {
  5.              console.log("2");
  6.              if (!event) { event = window.event; } // ie suq
  7.              console.log("3; " + window.veent);
  8.              alert('Estimado usuario, este sitio se encuentra activo en otra pestaƱa del navegador.');
  9.              //location.href = "../../../FinSesion.aspx";
  10.              if (!event.newValue) return;          // do nothing if no value to work with
  11.              console.log("4");
  12.              if (event.key == 'getSessionStorage') {
  13.                  console.log("5");
  14.                  // another tab asked for the sessionStorage -> send it
  15.                  localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage));
  16.                  console.log("6; " + sessionStorage);
  17.                  // the other tab should now have it, so we're done with it.
  18.                  localStorage.removeItem('sessionStorage'); // <- could do short timeout as well.
  19.                  console.log("7");
  20.              } else if (event.key == 'sessionStorage' && !sessionStorage.length) {
  21.                  console.log("8; " + sessionStorage.length);
  22.                  // another tab sent data <- get it
  23.                  var data = JSON.parse(event.newValue);
  24.                  console.log("9");
  25.                  for (var key in data) {
  26.                      console.log("10; " + data[key]);
  27.                      sessionStorage.setItem(key, data[key]);
  28.                  }
  29.                  console.log("11");
  30.              }
  31.              console.log("12");
  32.          };
  33.          // listen for changes to localStorage
  34.          if (window.addEventListener) {
  35.              console.log("13");
  36.              window.addEventListener("storage", sessionStorage_transfer, false);
  37.              console.log("14; " + sessionStorage_transfer.length);
  38.          } else {
  39.              console.log("15");
  40.              window.attachEvent("onstorage", sessionStorage_transfer);
  41.              console.log("16");
  42.          };
  43.  
  44.          console.log("17");
  45.          // Ask other tabs for session storage (this is ONLY to trigger event)
  46.          if (!sessionStorage.length) {
  47.              console.log("18; " + sessionStorage.length);
  48.              localStorage.setItem('getSessionStorage', 'foobar');
  49.              console.log("19");
  50.              localStorage.removeItem('getSessionStorage', 'foobar');
  51.              console.log("20");
  52.          };
  53.          console.log("21");
  54.     </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top