I'm using the code that netadictos posted to the question here. All I want to do is to display a warning when a user is navigating away from or closing a window/tab.
The code that netadictos posted seems to work fine in IE7, FF 3.0.5, Safari 3.2.1, and Chrome but it doesn't work in Opera v9.63. Does anyone know of way of doing the same thing in Opera?
Thx, Trev
Opera does not support window.onbeforeunload at the moment. It will be supported in some future version, but has not been a sufficiently high priority to get implemented as of Opera 11.
onbeforeunload is now supported in Opera 15 based on the WebKit engine but not in any prior versions based on Presto.
Have you tried this?
history.navigationMode = 'compatible';
Reference, found via this page
I haven't actually tried it myself, but it looks promising.
Mobile Safari (iPhone/iPad) also doesn't support onbeforeunload, and I strongly suspect it is not likely to.
For detecting back/forward navigation there may be workarounds e.g. see Is there an alternative method to use onbeforeunload in mobile safari?.
Related
MDN says that window.focus() is compatible with IE https://developer.mozilla.org/en-US/docs/Web/API/Window/focus.
But if I open IE and write
x=window.open('https://blank.org')
And after I come back to the main tab and I do x.focus() is not working.
I found several similar posts, but they are all old, and the information referred to there is out of date.
Is this happening by default, or is a IE setting?
I can reproduce the issue in IE 11. I searched docs and find that it might be due to some security issues the method can't be used in IE 8+. You can refer to this article:
Windows Internet Explorer 8 and later. The focus method no longer brings child windows (such as those created with the open method) to the foreground.
It can work in modern browsers because they have different engines than IE so the function can work.
Looking in this site I see in the browser compatibility section, it looks like this
What does that mean? What do I have to do to use that property in safari?
If I go element.scrollTop, that works just like that?
Webkit is the browser engine used by Safari and Chrome, the mentioned item in MDN it's only to clarify that all versions in Safari that use webkit (since like forever) support the property perfectly.
Nothing to worry about, just use it wisely as you would with any other modern browser
I am willing to detect if the tab is in focus on as many mobile browsers as possible.
I saw that the common use in determining visibility is "document.hidden" or "document.visibilityState", but on https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden#Browser_compatibility is listed that it's not compatible on IE mobile.
Found also that many use document.addEventListener("visibilitychange", function() {}) - which also seems to might not be compatible on IE Mobile.
Another less common use is document.hasFocus() which is not supported in Opera Mini and might not be supported in Safari and Mobile Chrome..
plus, the "window.onblur" doesn't seem to work on chrome emulator.
Anyone knows maybe another way to check if the browser is in focus on all mobile browsers? or maybe one of the above is actually compatible to all?
Have you tried using the two events:
window.onfocus and window.onblur?
You can associate code which triggers when it focuses and it blurs, so actually you can detect when it's not focused
Does anyone have any idea whether the javascript function window.resizeTo() support is removed from safari browser version 10.11.4. Its working for lower versions of safari browser.
I also tried using the w3schools link and the resize does not happen.
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_resizeby_resizeto
Can anyone please confirm this?
I'm working with 'deviceorientation' on my laptop and an example jsfiddle seems to work fine in Chrome but is not responding in Firefox. I think that line 15 of JS is not working somehow...
window.addEventListener('deviceorientation', devOrientHandler, false);
The MozOrientation version on line 18 doesn't seem to be picking up the slack
window.addEventListener('MozOrientation', mozDevOrientHandler, false);
Just updated Firefox. And no change. I've tried to test on a desktop and (unsurprisingly) the machine doesn't seem to have the necessary accelerometers/sensors so the fiddle doesn't work on any browser on that machine. I've been scouring questions, reading the w3c specs, the MDN support and I still can't get it.
Does anybody know if this is a Firefox issue? Did I mess up settings or something? Any help is much appreciated. Any ideas as to why that example jsfiddle isn't working on Firefox?
note: the example "green ball" in the MDN link above isn't working on FF either. First time asking a question on SO.
Thanks!
Edit: I should clarify that the jsfiddle is the best example I could find, and is NOT my code. I believe it was from HTML5rocks.com but I can't find that source.
Firefox does not, at this time of writing, expose DeviceOrientation events on any Desktop platform. Your event handler is not triggered in Firefox simply for the reason that the API is not enabled in their Desktop browser builds.
On the other hand, Chromium-based browsers have enabled DeviceOrientation events with some important caveats. Chromium-based browsers generally only return DeviceOrientation events consistently on Mac OS X due to the general availability of gyro + accelerometer hardware sensors that are available in Apple computers. Additionally, Chromium-based browsers report the event.alpha value as undefined due to no compass or magnetic sensors being available to compute that correctly.
The situation on mobile browsers is much better and is arguably the main target for this API. All major mobile browsers (Safari on iOS, Chrome/Opera/Firefox on Android) do support this event in its un-prefixed form i.e. window.addEventListener('deviceorientation', function(event) { /* ... */ }, false).