How to check if mouse is over a notification window in Chrome? - javascript

http://developer.chrome.com/extensions/notifications.html
I need to close the notification window after X seconds only if user's mouse is not over the notification window being displayed.
var notification = webkitNotifications.createNotification(
'icon.png',
'Notification titile',
'Notification body text'
);
notification.show();
// TODO: Close notification window only if user's mouse is not over it
setTimeout(function() { notification.cancel() }, 10000);

I haven't touched Chrome extensions for a while but the last time I did, you could use a HTML file as content for the notification.
So what I'd do is:
If you can close the notification with JavaScript inside the notification, then just use the normal onmouseover/onmouseout to store in a boolean if the mouse is on the notification or not and launch the time out from within the notification as soon as it gets loaded.
If you can't do the same thing but have the notification talk to the background page to make it close the notification.

Related

Open minimised chrome extension window on notification click

How to focus on minimised chrome extension window when chrome notification click
This is my current code. It is not getting click event
chrome.notifications.onClicked.addListener(function(notifId) {
console.log('inside notification click listener', notifId);
chrome.windows.update(winId, { focused: true });
});
I want send notification in chrome extension. when i click the notification it should focus to the chrome extension window
You can use the chrome.windows.getCurrent method to get the ID of the current window, and then use that ID in the chrome.windows.update method to focus the window. Try this
chrome.notifications.onClicked.addListener(function(notifId) {
console.log('inside notification click listener', notifId);
chrome.windows.getCurrent({}, function(window) {
chrome.windows.update(window.id, {focused: true});
});});
This code first gets the current window using chrome.windows.getCurrent, and then updates the focused property of the window to true in the chrome.windows.update method.

Alert user to navigate less in browser window

I am creating an online exam platform, so I don't want the user to navigate and close the browser. I have used an onblur event and visibility api. Both have limitations.
For example, onblur triggers even when the window is open and the user clicks on empty space in toolbar of the computer. The visibility api only works if the browser window is minimized. It's not applicable if it is overlapped by another window.
$(window).blur(function() {
document.addEventListener("visibilitychange", function() {
if (document.hidden) {
alert('blur');
} else {
console.log("Browser tab is visible")
}
});
})

html5 desktop notification pagevisibility close

I'm working with desktop notifications everything works fine here is the code I'm using:
function notifyMe(title,icon,body,tag) {
var notification = new Notification(title, {
icon: icon,
body: body,
tag: tag
});
setTimeout(function(){
notification.close();
},6000);
}
Now what I want is how I can close the notification without showing a notification for example if a notification is appearing , how can I close it from another function or something like that. because I want to work with pagevisibility when tab is hidden it will show notification and when tab is visible I want to hide the notification.

Show a alert when the user close the window when the audio is playing

I use the MediaElement.js framework to build my audio players...
But, is a podcast and is normal see users closing the window accidentally.
I'm searching for scripts to this, but absolutely nothing works.
How alert the user when he close the window with the player working...?
If is playing: ask if the user really want this.
If the player isn't playing: close the window..
Add an event as follows:
$(window).bind("beforeunload", function(evt) {//gets called before the user leaves the page
//check if audio is already running
if(isPlayingAudio()) {
//shows a confirm message asking user if they want to stay
return "Are you sure you want to leave while playing music?";
}
})
If your elements are on the page and not stored in javascript
function isPlayingAudio() {
var $playing = $('audio').filter(function(i, $audio) {//all audio not paused
return !$audio.prop('paused');
});
return $playing.length === 0;//no audio elements are playing...
}

how to detect chrome camera access dialog is open

how i can detect google chrome camera access dialog open or not I can detect what user choose allow or deny but can't detect dialog is open or not I need show a little tip under it for that I need detect open it or not ... I open it by default but if user choose deny second time it's not open
I don't believe that there's actually a way to detect if the dialog is open, but you might be able to infer that it's open. Show your tip each time you call getUserMedia(), and hide it on the callback or any other user interaction with your page (assumption being they denied video access if they're doing other stuff on the page)...
$("#tooltip").show();
navigator.webkitGetUserMedia({"video":true}, function(stream) {
$("#tooltip").hide();
// Do your thing.
});
You could also put a delay on showing the tip so it's only shown if the video stream callback doesn't happen for a specified period of time:
var tipTimeout = setTimeout(function() {
$("#tooltip").show();
}, 1000);
navigator.webkitGetUserMedia({"video":true}, function(stream) {
clearTimeout(tipTimeout);
$("#tooltip").hide();
// Do your thing.
});
Hope this helps!

Categories