让浏览器选项卡闪烁通知

发布于 2024-10-06 19:11:37 字数 298 浏览 4 评论 0原文

出于安全原因,我的网站会在用户闲置 5 分钟后自动注销。我通过 jquery 超时来实现这一点,每当用户执行我认为的“活动”时,超时就会重置。为了确保安全,cookie的超时时间也设置为5分钟,并且我的jquery向服务器执行心跳以确保cookie不会过期。

目前,在大约 4 分钟不活动时,会弹出一个 jquery ui 对话框,警告用户即将超时。用户可以选择保持登录状态、立即注销或不执行任何操作,并在 5 分钟结束时被迫注销。

我的问题是我想让选项卡以不同的背景颜色闪烁,以警告用户在他们不注意的时候发生了一些事情。我只是不确定如何去做这件事。

For security reasons, my website automatically signs users out after 5 minutes of inactivity. I achieve this through jquery timeouts which are reset any time the user does what I consider an "activity". To ensure security, the timeout of the cookie is also set to 5 minutes, and my jquery performs a heartbeat back to the server to ensure the cookie doesn't expire.

Currently, at about 4 minutes of inactivity, a jquery ui dialog pops up, warning the user of their impending timeout. The user can choose to stay signed in, sign out now, or do nothing and they are forced to sign out at the end of the 5 minutes.

My problem is that I want to make the tab flash/blink with a different background color to warn the user that something is going on while they weren't paying attention. I'm just not sure how to go about doing this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

追我者格杀勿论 2024-10-13 19:11:37

您可以更改页面的标题(这也应该更改选项卡中的文本)。

document.title = 'New title';

此外,您可以在页面标题和尝试向用户显示的信息之间来回使用 setInterval 来执行此操作。我在 Gmail 上看到了传入聊天通信的这种行为。

You can change the title of the page (this should also change the text in the tab).

document.title = 'New title';

Additionally you could do this in a setInterval back and forth between the page title, and the information you are attempting to show the user. I have seen this behavior on gmail with incoming chat communication.

情痴 2024-10-13 19:11:37

无法更改浏览器选项卡的背景,至少不能在所有选项卡中保持一致。

正如 Josiah 提到的,setInterval 可用于创建闪烁的页面标题。

这个 javascript 利用了它:

var PageTitleNotification = {
    Vars:{
        OriginalTitle: document.title,
        Interval: null
    },    
    On: function(notification, intervalSpeed){
        var _this = this;
        _this.Vars.Interval = setInterval(function(){
             document.title = (_this.Vars.OriginalTitle == document.title)
                                 ? notification
                                 : _this.Vars.OriginalTitle;
        }, (intervalSpeed) ? intervalSpeed : 1000);
    },
    Off: function(){
        clearInterval(this.Vars.Interval);
        document.title = this.Vars.OriginalTitle;   
    }
}

可以像这样使用:

PageTitleNotification.On("User logged out!");

请参阅我的以下博客文章以获取更多信息:

http://curtistimson.co.uk/js/create-a-flashing-tab-notification-page-title/

It's not possible to change the background of a browser tab, at least not consistently across all.

As Josiah has mentioned, setInterval can be used to create a flashing page title.

This javascript makes use of it:

var PageTitleNotification = {
    Vars:{
        OriginalTitle: document.title,
        Interval: null
    },    
    On: function(notification, intervalSpeed){
        var _this = this;
        _this.Vars.Interval = setInterval(function(){
             document.title = (_this.Vars.OriginalTitle == document.title)
                                 ? notification
                                 : _this.Vars.OriginalTitle;
        }, (intervalSpeed) ? intervalSpeed : 1000);
    },
    Off: function(){
        clearInterval(this.Vars.Interval);
        document.title = this.Vars.OriginalTitle;   
    }
}

This can be used like:

PageTitleNotification.On("User logged out!");

See my following blog post for more info:

http://curtistimson.co.uk/js/create-a-flashing-tab-notification-page-title/

反差帅 2024-10-13 19:11:37

您还可以添加警报窗口。当用户位于另一个选项卡中时,浏览器具有闪烁选项卡(具有警报)的内置功能。因此,更改文档标题和警报将达到您的目的。注意:在显示警报之前,您需要首先检查选项卡是否处于活动状态。

You can also add an alert window. When user is in another tab, browser has an inbuilt feature of flashing the tabs (having alert). So, changing document title along with an alert will serve your purpose. Note : before showing alert , you need to first check if tab is active.

您可以更改页面标题并将其显示在浏览器选项卡中,但无法更改背景颜色或使其闪烁

you can change the page title and that will show in the browser tab, but you can't change the background color or make it blink

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文