i'm new at programming and im looking for a way to display an alert whenever the user is in the web or not. i've tried with alert() (the one in http://www.w3schools.com/jsref/met_win_alert.asp) using a timer to test it, but the alert only displays in the tab and not over every application running in the desktop.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display an alert box.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
alert("Hello! I am an alert box!");
}
</script>
</body>
</html>
If there's a solution in other languages i'm open to try them. thanks.
Based on the link you've shared, if you want a popup over any desktop application through the browser, use the W3C Notification API. For example
window.onload = function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
};
function notifyMe() {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
icon: 'Notification icon',
body: "Notification body",
});
notification.onclick = function () {};
}
}
and call the notifyMe()
using the navigator online variable. For example
setInterval(function () {
if (navigator.onLine)
notifyMe();
}, 1000);
This will check whether user is connected to internet every 1 second and display a popup if true.
See https://developer.mozilla.org/en/docs/Online_and_offline_events