Javascript:在不使用警报框的情况下提醒用户
我正在尝试找到一种优雅的方式来通知用户他/她即将注销,并且我知道大多数浏览器都会向您提供一些指示,表明隐藏选项卡打开了警报框。我想复制此功能而不实际显示警报框。
我曾考虑过强制选项卡/窗口获得焦点,但这非常唐突,我讨厌网站对我这样做,所以我正在寻找更微妙的东西。
有什么想法吗?
编辑/说明:我已经有了一个在他们即将注销时弹出的 div。我的问题是,如果他们在另一个选项卡上,他们将无法看到该 div,所以我想要某种方式来通知用户我的选项卡上发生了重要的事情,以便他们检查并查看注销注意。
下面列出的图标创意是一个很好的创意,还有其他创意吗?
I'm trying to find an elegant way to inform a user that s/he is about to be logged out and I know that most browsers will give you some indication that a hidden tab has an alert box open. I would like to duplicate this functionality without actually showing an alert box.
I have thought about forcing the tab/window to gain focus, but that is quite obtrusive and I hate it when websites do that to me, so I'm looking for something a little more subtle.
Any ideas?
Edit/Clarification: I already have a div that pops up if they are about to be logged out. My problem is that if they are on another tab, they won't be able to see that div, so I would like some way to notify the user that something important has happened on my tab so they go check it out and see the logout notice.
The favicon idea listed below is an excellent idea, any others?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我想到了一种有趣的方式。当需要注销时,动态更改网站的图标。较新的浏览器应该可以接受。
请看这里:动态更改网站图标
Here's an interesting way that comes to mind. When its time to be logged out, change the website's favicon dynamically. Newer browsers should be ok with it.
Look here: Changing website favicon dynamically
我见过的一些技术:
Some techniques I've seen:
您可以创建一个页面,通知他们将在一定时间内注销,并使用一个按钮让他们保持会话。或者您可以使用灯箱模式弹出窗口(例如此处)。
You could create a page that informs them they will be logged out in a certain amount of time with a button that would allow them to maintain their session. Or maybe you could use a lightbox modal popup window (example here).
为什么不换出您想要更改的 div 样式,让他们知道他们很快就会退出?然后,您可以简单地将其作为页面的一部分,具有相同的样式和格式吗?
例如,您的普通页面具有某种带有visibility:block;的页面元素。然后在他们注销之前,将其更改为visibility:none;并更改您的其他元素(在同一位置)以具有可见性:块;
这个想法有道理吗?您必须能够检测到何时发生这种情况,并且 Javascript 已经发出警报,因此您只需更换显示元素即可,而不是进行更改。
我希望这对您有所帮助,
-Brian J. Stinar-
Why not swap out a div styled how you want to change to let them know they will be logged out soon? Then, you can simply have it as a portion of your page with all the same style and formatting?
For example, your normal page has some sort of page element with visibility:block; and then before they will be logged out, you change that to visibility:none; and change your other element (in the same place) to have visibility:block;
Does this idea make sense? You have to be able to detect when this is happening with Javascript already to alert, so instead of altering you are just swapping out display elements.
I hope this is helpful,
-Brian J. Stinar-
它可能不符合您的需求,但简单的模态窗口可能是个好主意?我知道它不会立即提醒用户,除非他们切换回该选项卡,否则他们不会看到它,但它并不引人注目,我相信大多数用户不希望有东西撞到他们的脸上!
如果此通知是由用户单击“注销”或类似操作触发的,那么他们会看到它,并且不会像强迫他们停止正在做的事情并关闭警报框那样具有侵入性。
如果是由于超时或类似的原因,那么用户不会过度担心,或者他们仍然会在该选项卡上。
我认为这在可用性方面达到了最佳目的,因为人们不想被打扰或因为向他们推送警报而破坏他们的工作流程!一个完美的例子是 Microsoft TFS,当您注销时,它会不断地向您发出警报,这非常令人沮丧,而且很快,
所以我的答案是考虑用户希望如何以最不唐突的方式收到通知:-)
it probably doesn't go with what you're after but a simple modal window is probably a good idea? i know it doesn't alert the user instantly, and they won't see it unless they switch back to that tab, but it's unobtrusive and i believe most users would prefer not to have something rammed in their face!
If this notification is to be triggered by a user clicking "log out" or the likes then they will see it and it won't be as intrusive as forcing them to stop what they are doing and close the alert box.
And if it's due to time out or something similar then the user isn't overly concedrned or they would still be on that tab.
I think that this serves the best purpose in terms of usability as people don't want to be hassled or have their workflow broken by an alert shoved at them! A perfect example is Microsoft TFS which would constantly throw alerts at you when you got signed out, which got really frustrating, really quickly
so my answer is think how the user would like to be notified in the least obtrusive way :-)