I have a cordova app. I that I want do some task like stop the Location service when the user try to leave the page. I have tried the window.beforeunload but it didnt not work. Is there a way i can do this.
If you want to perform an action (do some task) before the user leaves your app, you can use the window.onunload event.
Related
I have an analytics service which uses
window.addEventListener('beforeunload', endSession);
to record the user navigating away from the app.
In another part of the app we have downloading functionality, using
window.location = urlOfItemToDownload;
This causes the beforeunload event to trigger, which is undesirable.
There are many downloads in the app so toggling a boolean variable isnt so scalable. Is there any way around it?
I work in a call center and we use an in-house app for dialing. The app is built using HTML/JavaScript for the front end and MSSQL/Node.js for the back end.
We have a problem where some people close the browser without logging out properly and this is causing data to be lost because the phone call is not being terminated correctly. Is there any way to prevent the user from closing the app using the 'X' button in Chrome?
I have already setup the generic Chrome message that warns of data loss if the browser is closed, but this isn't really doing the job.
I am looking for either some kind of JavaScript code to run in the app or perhaps something externally I can run on the local computer. Also, a Chrome startup command line switch would be perfect for the job too, but from my research, I am not sure one exists.
$(window).on("beforeunload", function() {
return confirm("Do you really want to close?");
})
There is no specific event for capturing browser close event.
You can only capture on unload of the current page.
By this method, it will be effected while refreshing / navigating the current page.
Ref
I'm writing a chrome extension which will perform some actions when a system notification pops up. Specifically, I want to close them.
For example: the "Restore pages?" notification:
My manifest file has nothing particularly interesting, here is my event page:
function anyAlarmHandler (Alarm anyAlarm) {
// For now, just clear any alarm when one pops up.
chrome.alarms.clear(anyAlarm);
}
chrome.alarms.onAlarm.addListener(anyAlarmHandler);
But it doesn't clear the system notification as expected.
I suspect that I'm listening for the wrong event, that system notifications are not actually considered an alarm. But the 'notifications' API doesn't have anything regarding catching notifications.
I've looked at this question regarding catching notifications, which might work, but it doesn't help with the following:
I need to catch notifications created by the browser itself, not another extension (this might not matter, I'm not sure)
I need to modify that notification. Change the text, close it, whatever.
I've tried using the code in the link above and just popping some dialogue box when a notification happens (to test if that solution works for detecting browser notifications), but even that didn't work. I'm hoping that I'm just missing some method/event listener in some API, but I can't seem to find it anywhere. Any help is appreciated.
You cannot detect, or override, any of the Chrome's own UI popups like this.
Only another native app could potentially interact with them (e.g. simulate a click).
Short of patching Chrome (in-memory or on disk), you won't be able to change the wording.
I am currently trying to manually develop an unsaved changes warning in our JSF-based Webapplication. Sadly our customer does not like the styling of the default warning displayed via an alert() after using the onbeforeunload event and requires us to develop a similar mechanism on our own.
I was thinking of using the way described here to prevent the onbeforeunload event from displaying the alert() and simply showing my own modal panel. I just can't figure out how to make the "Yes" (yes, I want to leave this page and lose all unsaved changes) button work. The button should basically resend the request which lead to the onbeforeunload event which could have been a HTTP Request as well as an Ajax Request. How would one do that via JS?
Thank you :)
Cheers
//edit: It needs to work in IE9 as well as Chrome 38
I would like to make the user confirm that she wants to leave my single-page application. ExtJS 4.1 provides the onWindowUnload in which I would like to plug in a Confirm dialog.
If the user decides to proceed closing the tab/window an Ajax request to the logout URL should tell the server-side that the user has logged out.
Is the above approach possible?
Is it possible to plug the onWindowUnload event in ExtJS MVC controller?
P.S. User leaving single-page app can be any of the following: browser tab close, browser window close, browser back button, browser forward button.
You need to add a listener to the window's onbeforeunload event.
It is a special type of event handler, and you should read the docs closely.
MDN docs: https://developer.mozilla.org/en/DOM/window.onbeforeunload
MS docs: http://msdn.microsoft.com/en-us/library/ie/ms536907(v=vs.85).aspx
Ext's standard way of attaching event handlers DOES NOT WORK† with this particular event.
You need to use the standard addEventListener or attachEvent methods.
Example:
http://jsfiddle.net/NhLQK/9/
Can I use my own dialog? No
Can I display my own message in Firefox? No
Can I use a confirm()? No
Can I make them look the same in different browsers? No
Can I fire an AJAX message before the user closes the browser? Yes,
if it's synchronous:
Ext.Ajax.request({
url:'some url',
async:false,
method:'POST'
});
† it seems to work in Chrome with ext 4.1.1