Windows Vista Tips

Windows Vista Tips > Newsgroups > Internet Explorer > IE localstorage.onstorage problem/bug

Reply
Thread Tools Display Modes

IE localstorage.onstorage problem/bug

 
 
buda
Guest
Posts: n/a

 
      03-31-2011
I hava main page which subsrcribes on onstorage event.
This page has a button to open some windows which also subcribe
onstorage event. These pages have a button to write some data into
localstorage.
The problem/bug is that the main window doesnt receive onstorage event
while the res do.

Main window
-----------------------------

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>
localStorage window broadcast example</h1>
<script type="text/javascript">

function openwindows(n) {
var h = window.screen.height / n,
w = window.screen.width / n, i, j;

for (i = 0; i < n; i += 1) {
for (j = 0; j < n; j += 1) {
window.open('1.htm', '_blank', "width=" + (w - 10) + ",height=" +
(h - 60) + ",resizable=yes,scrollbars=no,status=no,left=" + (i * w) +
",top=" + (j * h));
}
}
}

function openwindow() {
var h = window.screen.height,
w = window.screen.width;

window.open('1.htm', '_blank',
"width=200,height=200,resizable=yes,scrollbars=no, status=no,left=" +
(~ ~(Math.random() * w)) + ",top=" + (~ ~(Math.random() * h)));
}


function onStorage() {
var cmd = localStorage.getItem('command');

if (cmd.match(/close/)) {
window.close();
} else {
document.body.style.backgroundColor = 'rgb(' + ~ ~(cmd * 255) +
',' + ~ ~(cmd * 255) + ',' + ~ ~(cmd * 255) + ')';
document.body.style.color = 'rgb(' + ~ ~(Math.random() * 255) +
',' + ~ ~(Math.random() * 255) + ',' + ~ ~(Math.random() * 255) + ')';
}
}

var webkit = !!navigator.userAgent.match(/AppleWebKit\/(\d+\.\d+)/);

if (window.addEventListener) {
window.addEventListener("storage", onStorage, false);
} else {
window.attachEvent("onstorage", onStorage);
};

function broadcast(cmd) {
localStorage.setItem('command', cmd);
onStorage();
}

</script>
<button onclick="openwindow();">
Open 1 window</button>
<button onclick="openwindows(4);">
Open 16 windows</button>
<button onclick="openwindows(5);">
Open 25 windows</button>
<button onclick="broadcast(Math.random());">
Broadcast</button>
</body>
</html>


Opened windows = 1.htm
---------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Broadcast target</title>
</head>
<body>
<script type="text/javascript">
function onStorage() {
var cmd = localStorage.getItem('command');
document.getElementById("result").innerHTML = cmd;

if (cmd.match(/close/)) {
window.close();
} else {
document.body.style.backgroundColor = 'rgb(' + ~ ~(cmd * 255) +
',' + ~ ~(cmd * 255) + ',' + ~ ~(cmd * 255) + ')';
document.body.style.color = 'rgb(' + ~ ~(Math.random() * 255) +
',' + ~ ~(Math.random() * 255) + ',' + ~ ~(Math.random() * 255) + ')';
}
}

var webkit = !!navigator.userAgent.match(/AppleWebKit\/(\d+\.\d+)/);

if (window.addEventListener) {
window.addEventListener("storage", onStorage, false);
} else {
window.attachEvent("onstorage", onStorage);
};

function openwindow() {
var h = window.screen.height,
w = window.screen.width;

window.open('1.htm', '_blank',
"width=200,height=200,resizable=yes,scrollbars=no, status=no,left=" +
(~ ~(Math.random() * w)) + ",top=" + (~ ~(Math.random() * h)));
}

function broadcast(cmd) {
localStorage.setItem('command', cmd);
onStorage();
}

</script>
<button onclick="broadcast(Math.random());">
Broadcast</button>
<button onclick="broadcast('close-'+Math.random());">
Close all</button>
<button onclick="openwindow();">
Open Window</button>
<pre id="result"></pre>

</body>
</html>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59