1

I have built a Firefox 22 application in JavaScript/HTML5 and I would like to block the user from opening multiple instances of it (whether it be in a separate tab or a separate browser).

Currently this works to the extent that when you try to open another instance of it, it redirects to about:blank, brings the original instance of the application into focus (switches tab or window), and displays an alert (on the original instance). This is done checking a displayState variable I've set in localStorage.

The problem I've run into is that while the alert is up, the user can open as many instances of the application as he/she wants.

Is there a better way than using (a displayState check in) localStorage to do this? Or is there a way to keep the alert from timing-out the application?

4

1 回答 1

1

警报会阻止 Firefox 中的脚本执行(例如 Opera 并非如此),您几乎无法更改它。因此,您应该使用不同的东西。

尽管如此,您可以localStorage在应用程序启动时设置密钥并在关闭时取消设置 ( window.onunload)。但是,如果浏览器崩溃,用户可能会卡住。可以试试SessionStorage,关闭浏览器会自动清理。

于 2013-07-31T22:44:38.200 回答