简体   繁体   English

从Web应用程序显示系统任务栏通知或桌面通知

[英]Show a System Tray notification or Desktop notification from the web application

I have created a web application in Java using J2EE 6.0 that has login functionality. 我已经使用具有登录功能的J2EE 6.0在Java中创建了一个Web应用程序。 As the user logs in into the application, a timer start at 59:59 (minutes:seconds) and keeps on decreasing until it comes to 3:00. 当用户登录到应用程序时,计时器从59:59(分钟:秒)开始计时,并一直减少直到3:00。 When 3 minutes are left, it displays a popup to the user asking to logout or extend their time/session again back to 59:59. 剩下3分钟时,它将向用户显示一个弹出窗口 ,要求注销将他们的时间/会话再次延长至59:59。

My question is if user is doing some other work say on outlook or surfing some other thing over the internet in a new window/browser(Firefox,etc.). 我的问题是用户是否正在做其他工作,例如在Outlook上浏览还是在新窗口/浏览器(Firefox等)中通过Internet进行其他浏览。 How can I notify the user that his session/time is going to expire. 我如何通知用户他的会话/时间即将到期。 This application is intended to run only on Microsoft Windows Internet Explorer . 该应用程序只能在Microsoft Windows Internet Explorer上运行。

I found these links for displaying desktop notifications but unfortunately my application is specific to run on Internet Explorer only 我找到了这些用于显示桌面通知的链接,但是不幸的是我的应用程序特定于仅在Internet Explorer上运行

What ways are out there to display a desktop notification from a web app? 有哪些方法可以显示来自Web应用程序的桌面通知?

How do Stack Overflow desktop notifications work? Stack Overflow桌面通知如何工作?

So I cannot use Desktop notifications. 因此,我无法使用桌面通知。

I thought I would create a swing application to display the notification popup in the Windows System Tray saying 'Your session is going to expire'. 我以为我会创建一个Swing应用程序以在Windows系统托盘中显示通知弹出窗口,提示“您的会话即将到期”。 But I am stucked how will it run on the client machine. 但是我被困在它将如何在客户端计算机上运行。 I have heard of something called Java Web Start , AjaxSwing , etc. With Java Web Start software, users can launch a Java application by clicking a link in a web page. 我听说过Java Web StartAjaxSwing等。使用Java Web Start软件,用户可以通过单击网页中的链接来启动Java应用程序。 It requires JRE in the client system. 它需要客户端系统中的JRE。 Java Web Start will ask the user to download the Java plugin which will download a JRE(if not found in the client's system) which is annoying. Java Web Start将要求用户下载Java插件 ,该插件将下载令人讨厌的JRE(如果在客户端系统中找不到)。

AjaxSwing will convert the Swing app to HTML, Javascript and CSS so I am not sure how it will come out of a browser to show up a popup in System Tray. AjaxSwing会将Swing应用程序转换为HTML,Javascript和CSS,所以我不确定它将如何从浏览器中显示出来,以在系统托盘中显示弹出窗口。 I think that will remain stick to the browser. 我认为仍然会坚持使用浏览器。

I searched for blinking the tab option but it is not blinking the tab in the taskbar of the windows. 我搜索了闪烁的选项卡选项,但它没有闪烁Windows任务栏中的选项卡。

I read somewhere Growl for Windows but I am not sure whether it will be helpful for me or not. 在Windows的Growl上读过书但不确定是否对我有帮助。 Please tell that also. 也请告诉我。 Please suggest me how can I notify the user that his session is going to expire. 请建议我如何通知用户他的会话即将到期。 I already know I can notify through the email . 我已经知道我可以通过电子邮件通知。 Please help me with an innovative idea and solution to pursue further. 请提供创新的想法和解决方案,帮助我进一步发展。

我遇到了同样的问题,并使用了jQuery通知插件作为解决方法,您也可以在插件回调中使用“ onShow”播放声音或确保用户得到通知的任何方法

try it for Google Chrome: 尝试将其用于Google Chrome浏览器:

function notifyBrowser(title, desc, url) {
    if (Notification.permission !== "granted") {
        Notification.requestPermission();
    } else {
        var notification = new Notification(title, {
            icon: 'http://YourWebsite.com/logo.png',
            body: desc,
        });
        /* Remove the notification from Notification Center when clicked.*/
        notification.onclick = function() {
            window.open(url);
        };
        /* Callback function when the notification is closed. */
        notification.onclose = function() {
            console.log('Notification closed');
        };
    }
}

And so, only call the function : 因此,仅调用该函数:

notifyBrowser('Pay attention', 'You have new notifications', 'www.stackoverflow.com');

font: http://www.9lessons.info/2015/11/display-browser-notifications-from-web.html 字体: http//www.9lessons.info/2015/11/display-browser-notifications-from-web.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM