Closed Bug 264525 Opened 20 years ago Closed 12 years ago

onbeforeunload capability not detectable

Categories

(Core :: DOM: Events, enhancement)

1.7 Branch
x86
Windows XP
enhancement
Not set
normal

Tracking

()

RESOLVED WORKSFORME
mozilla9

People

(Reporter: rob, Unassigned)

References

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10.1

Using object detection rather than browser sniffing, there is no way to know
that Firefox supports the onbeforeunload event. If it is not assigned a value,
typeof(window.onbeforeunload) returns "undefined" and unfortunately so does
Opera (which does not support the event). If it is assigned a value,
typeof(window.onbeforeunload) returns "String" and unfortunately so does Opera.
(IE returns "String" if it is set and "object" if it is not.)

Reproducible: Always
Steps to Reproduce:




At this point, still not wanting to do browser detection, I will need to check 
onbeforeunload before I set it, and see whether it is an object. This means I
will only be able to use my onbeforeunload in IE, and not fully use the
capabilities of Firefox.
javascript:window.onbeforeunload = function() { alert(5); }; alert(typeof
window.onbeforeunload)

I get "function", not "string".

Why do you need to check for onbeforeunload support before setting the
onbeforeunload function, anyway?
Assignee: firefox → events
Component: General → DOM: Events
Product: Firefox → Browser
QA Contact: firefox.general → ian
Version: unspecified → 1.7 Branch
If I express the script as an anonymous function rather than a string, I get
"function" also.  The problem is I still get the same thing from Opera.

The overall issue is, I am trying to detect whether the browser supports the
onbeforeunload event or not. I can check before or after I set it, I just need
to know if the browser is going to support it. So far, in any way I can figure
out to test it, Firefox and Opera are always reporting the same values, even
though Firefox supports it and Opera doesn't. (Try your script in Opera --
you'll still get "function", but if you leave the page, you won't get your "5".)
Severity: minor → enhancement
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee: events → nobody
QA Contact: ian → events
Many time I wish we had this, I put a suggestion a whatwg 
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-September/028634.html
jonas sicking recommend to implement  
  'onbeforeunload' in document.body ==> true
Dupe of #414853 ?
Depends on: 414853
Fixed in bug 659350.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WORKSFORME
Target Milestone: --- → mozilla9
You need to log in before you can comment on or make changes to this bug.