cross-browser Onunload and Onbeforeunload ? (particularly opera 11) - javascript

I have a form and I must notice user with alert() on exiting page while there are data in the form that had not been send.
I've read that opera has a lot of problems with this. Opera 11 that is, because I need take into account only last version.
So again, the alert should display on refresh, closing a tab, or closing whole browser.
It would be nice to set event directly to the <form> element that would be launched on anything that leads to destroying this element.

Opera does not yet support onbeforeunload. Opera's onunload support is incomplete - for example, it does not fire when you close a tab, or close Opera. As far as I know, while you can use onunload to show a warning if a user clicks a link to navigate away from a page with an unsaved form, there is no way you can prevent the navigation from happening when the unload event fires.
What I would do here is to listen for the onbeforeunload event, make it work in other browsers and wait for Opera to catch up. Whether it will be in Opera 12 or 13 or 15 I don't know, but when onbeforeunload is implemented it will work like it does in other browsers already.

The Disable Close will not help you yet because Opera does not support window.onbeforeunload at the moment. It will be supported in some future version. For now, Opera 11 doesn't implement it.

onbeforeunload is now supported since Opera 15 !

The JQuery framework is only a condensed Javascript language so it depends entirely on the browser you use, no magic here.

Related

Trying to prevent an alert when using beforeunload. preventDefault works in Chrome but not in Firefox

The below code is working in Chrome but it's not working in Firefox. Firefox is showing a popup as we leave the page as
This page is asking you to confirm that you want to leave - data you have entered may not be saved.
window.addEventListener("beforeunload", function (e) {
e.preventDefault();
});
As pointed in the mozilla docs:
According to the specification, to show the confirmation dialog an
event handler should call preventDefault() on the event. However note
that not all browsers support this method...
This is a good article about when you should use the beforeunload event. Check it out cuz you might not need it.
And here's a polifill that claims to support...
newer ES5 compatible browsers. And it should be able to support most elderly browsers if you provide them with an ES5 shim.

Detecting FF browser being closed (X) in 2018

A requirement from the customer is to immediately detect that the browser is closed and canceling the session opened from it. This calls for detecting the browser closing event with the onbeforeunload and calling there our logout Servlet from a XmlHttpRequest. It may have worked in the past but today it doesn't work anymore.
After hours of googling and testing I could not come up with a decent solution that detects browser closing on Firefox. I can more or less detect it on other browsers but not on FF. Actually I cannot even catch 100% of the times the event of a tab being closed. Sometimes it works, sometimes it doesn't. Frustrating.
Does anyone in 2018 has a working example to share, that effectively detects on new FF browsers the closing event?

Onbeforeunload fires before onhashchange in IE10?

We use both onbeforeunload and onhashchange to do two separate things:
1) onhashchange displays a special tooltip asking the user to use application controls for navigation
2) onbeforeunload is used to warn the user that they will loose data if they close the app or try to navigate away to a different URL altogether
This implementation works perfectly on all browsers but IE10. For some reason in IE10, onbeforeunload fires before onhashchange and it causes the wrong thing to display.
Is this a known issue? Is there something special about IE10 I need to know?
Implementation is in Dojo, if that helps...

Use javascript to find the current url from address bar in IE8

I change the bookmark in the url when the page is loaded. That way, when the user clicks the back button of the browser, the browser will not actually go back, but will instead change the bookmark. I can then detect the bookmark change and do something else as a reaction to the user pressing the back button.
My problem is to find the current url, including any bookmark/hash changes. It works in all browsers, using a combination of the following, but not in IE8:
document.URL
location.href
window.location.hash
and the window.onhashchange
As it doesn't work for IE8, could anyone possibly point me in the right direction towards how I can detect the bookmark/hash change in IE8?
Look at jquery-bbq, as it implements the hashchange and makes it work in IE6-IE8 and possibly IE9 now. You could probably entirely rely on it instead of your custom code.
According to the author of the jQuery hashchange plugin, IE8 supports binding to the window.onhashchange event out of the box.
Perhaps you could try using Ben's plugin, which is intended to enable hash change detection on older browsers.
EDIT: My tests showed that the event is not firing in IE8. Then I found the following comment in above plugin's source code:
// Note that IE8 running in
// IE7 compatibility mode reports true for 'onhashchange' in window, even
// though the event isn't supported, so also test document.documentMode.
Apparently, I'm running in documentMode 5 which is quirks mode. I bet it works in IE8 standards mode only. Regardless, you should be able to implement the same JS code that Ben used.

How to focus window/tab like alert()?

If in some of my tabs alert() is executed, then this tab becomes selected instantly. The thing is - this alert() box is ugly. I have created with my design and all.. But when I call it - tab is not selected/focused.
window.focus(); does not work. Any ideas?
You cannot reliably force windows or tabs to grab focus. Some browsers are more amenable to the idea than others: IE will generally allow it, but Firefox has to be configured by the user to allow it, and Safari will basically never honor a focus request. (Well, almost never.)

Categories

Resources