admin管理员组文章数量:1394991
I have some JavaScript that will look to see if a var is set, if it is set then do something if not don't.
if (reset === 'reset') {
gallery.unformat(container);
}
reset
is only set once the page has loaded. So this script will only execute after the user reloads the page.
If i open a new tab in firefox reset
isn't set. If i open a new tab in chrome reset
is set.
So for my case chrome handles it correctly and only on the first going to the site does this var get set and thus everything works correctly.
I want to know is do variables propagate across tabs and if so which browsers do what?
I have some JavaScript that will look to see if a var is set, if it is set then do something if not don't.
if (reset === 'reset') {
gallery.unformat(container);
}
reset
is only set once the page has loaded. So this script will only execute after the user reloads the page.
If i open a new tab in firefox reset
isn't set. If i open a new tab in chrome reset
is set.
So for my case chrome handles it correctly and only on the first going to the site does this var get set and thus everything works correctly.
I want to know is do variables propagate across tabs and if so which browsers do what?
Share Improve this question edited Sep 23, 2014 at 4:48 infused 24.4k13 gold badges70 silver badges79 bronze badges asked Jul 19, 2012 at 9:40 Jamie HutberJamie Hutber 28.1k54 gold badges194 silver badges313 bronze badges2 Answers
Reset to default 6Variables should not persist across new tabs. I can't reproduce the behaviour you see in Chrome.
You should looking at using cookies
, or if you want to be HTML5, look at localStorage
.
Both of these are domain specific, rather than per-tab.
E.g. in localStorage
, you could go for;
// Check that localStorage is supported in the current browser, and then try
// to retrieve the item.
if ('localStorage' in window && localStorage.getItem('reset') === 'reset') {
gallery.unformat(container);
}
You'd then be able to set reset
later via;
localStorage.setItem('reset', 'reset');
No, variable values should not propagate between tabs - each tab should have its own global namespace, there would be all kinds of security issues if one tab could affect the JavaScript in another.
本文标签: Do browsers propagate javascript variables across tabsStack Overflow
版权声明:本文标题:Do browsers propagate javascript variables across tabs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744110584a2591274.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论