Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make sure that we don't bind the onunload event in Opera.
  • Loading branch information
jeresig committed Dec 19, 2009
1 parent 3fd62ea commit 1feb92a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -882,7 +882,7 @@ jQuery.each( ("blur focus load resize scroll unload click dblclick " +
// Window isn't included so as not to unbind existing unload events
// More info:
// - http://isaacschlueter.com/2006/10/msie-memory-leaks/
if ( window.attachEvent ) {
if ( window.attachEvent && !window.addEventListener ) {
window.attachEvent("onunload", function() {
for ( var id in jQuery.cache ) {
if ( jQuery.cache[ id ].handle ) {
Expand Down

8 comments on commit 1feb92a

@jeresig
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to thank kangax for the recommendation!

@NV
Copy link

@NV NV commented on 1feb92a Dec 20, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why not

if ( window.attachEvent && /*@cc_on 1 */ ) {

?

@NV
Copy link

@NV NV commented on 1feb92a Dec 20, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot "@"
if ( window.attachEvent && /@cc_on 1 @/ ) {

@kangax
Copy link

@kangax kangax commented on 1feb92a Dec 21, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NV
Or just — if (/*@cc_on ! @*/0). I guess removal of conditional comments is to cater to Closure Compiler (which strips them). if (window.attachEvent && !window.addEventListener) is a decent inference, but might fail when someone defines custom addEventListener on window (as, for example, MSDN demonstrates — http://msdn.microsoft.com/en-us/library/dd229916%28VS.85%29.aspx). The chance of someone following MSDN example is too big, as for my taste, so I'd rather go with something similar to what Garrett does in APE — var isMaybeLeak/*@cc_on=(@_jscript_version<5.7)@*/ (http://github.com/GarrettS/ape-javascript-library/blob/master/src/EventPublisher.js)

@NV
Copy link

@NV NV commented on 1feb92a Dec 21, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kangax, you are right about if (/*@cc_on ! @*/0). My code doesn't even work.

isMaybeLeak/*@cc_on=(@_jscript_version<5.7)@*/ looks much bulletproof.

@dmethvin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Closure compiler strips out comments, so I think the goal was to eliminate conditional comments completely from jQuery so that it is easy to build the compressed version.

@DBJDBJ
Copy link

@DBJDBJ DBJDBJ commented on 1feb92a Dec 21, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The just do not use the "closure compiler", I guess ?
Is Microsoft Ajax Minifier any good?
http://stephenwalther.com/blog/archive/2009/10/16/using-the-new-microsoft-ajax-minifier.aspx

@dmethvin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MS tool also strips out conditional comments, it seems:

http://ajaxian.com/archives/microsoft-ajax-minifier-vs-yui-compressor

Please sign in to comment.