区分F5或公开赛浏览器 [英] Distinguish F5 or Open for Browser
问题描述
是否有可能区分F5或Open(点击链接,粘贴URL在空白页面或新标签等)浏览器?
Is it possible to distinguish F5 or Open (click on link, paste URL in empty page or new tab, etc.) for Browser?
为什么呢?因为我想,以提高用户界面的人机工程学。在我的应用程序使用的一些昂贵的计算,以呈现页面。所以页面缓存并没有在网页重新计算。额外按钮
Why? Because I'd like to improve ergonomics of user interface. In my application some costly computations used to render a page. So page is cached and there is additional button on the page "Recalculate".
我不喜欢有额外的重新计算按钮时,恰好有相同的标准F5键。
I don't like having additional "Recalculate" button when there are exactly the same standard "F5" button.
我同时控制服务器和放大器;客户端JS,有没有被通知F5事件的任何方式?
I control both Server & Client JS, is there any way to be notified about "F5" event?
来检测所有的F5事件,并不会错过这是很重要的。但它是确定有有时(但有时不经常)额外的虚假F5事件 - 当打开页面已经被错误地检测为F5
It is important to detect all "F5" events and not miss it. But it is ok to have sometimes (sometimes but not frequently) additional false "F5" events - when Open Page has been mistakenly detected as "F5".
推荐答案
在你的情况下,使用的sessionStorage
听起来像你最好的选择。
In your case, using sessionStorage
sounds like your best option.
是这样的:
var calculatedValues = (function() {
var savedValues = sessionStorage.getItem("values");
if (!savedValues) {
// Do calculations
var values = {
result: 10
};
savedValues = JSON.stringify(values);
sessionStorage.setItem("values", savedValues);
}
return JSON.parse(savedValues);
}());
的sessionStorage
应该是每一个窗口独一无二的 - 去到页面在不同窗口将看不到任何数值并重新计算,而是pressing F5
不会的。
sessionStorage
should be unique for every window -- going to to the page under a different window will see no values and recalculate, but pressing F5
won't.
有些浏览器的将会的使用打开新的标签页
中的链接时,复制会话值从一个窗口到另一个,但它听起来像韩元'T是在这种情况下一个问题。
Some browsers will copy session values from one window to another when using Open in new tab
on a link, but it sounds like that won't be an issue in this case.
这篇关于区分F5或公开赛浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!