Side navigation
#4534 closed bug (invalid)
Opened April 13, 2009 11:39PM UTC
Closed June 12, 2010 06:08PM UTC
2 instances of jQuery kills unbind
Reported by: | ptarjan | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | unfiled | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Steps to recreate :
- http://paul.slowgeek.com/nodeSelector/dev/bad-unbind.html
- Click the "Add key listener"
- Press keys and notice they are printed
- Press ESC and see it says "unbinding"
- Press more keys and see they AREN'T printed
- Click the "add key listener" again
- Press keys and see they ARE printed
- Press ESC and see it says "unbinding"
- Press keys and see they ARE printed (this is the bad part)
If I change the javascript code to NOT add the jQuery library, then it works as expected.
Pasting Code incase my site is down:
--- bad-unbind.html
<a href='
javascript:(
function() {
var s=document.createElement("script");
s.charset="UTF-8";
s.src="bad-unbind.js";
document.body.appendChild(s)
})();
'>Add key listener</a>
<p id='key'></p>
--- end
--- bad-unbind.js
addLibs = function () {
if (typeof(document.body) == "undefined" || document.body == null) {
setTimeout(addLibs, 100);
return;
}
This line makes it work
if (typeof($) == "undefined") {
node = document.createElement("script");
node.src = "http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js";
document.body.appendChild(node);
}
addEvents();
}
addEvents = function () {
if (typeof($) == "undefined" || $("*") == null) {
setTimeout(addEvents, 100);
return;
}
var keydown = function(e) {
if (e.keyCode == undefined && e.charCode != undefined) e.keyCode = e.charCode;
$("#key").html("keydown " + e.keyCode);
Escape key
if (e.keyCode == 27) {
$("#key").html("unbinding");
$(document).unbind("keydown", keydown);
}
};
$(document).keydown(keydown);
}
addLibs();
--- end
Attachments (0)
Change History (2)
Changed December 08, 2009 12:24AM UTC by comment:1
Changed June 12, 2010 06:08PM UTC by comment:2
resolution: | → invalid |
---|---|
status: | new → closed |
It's okay to load two copies of jQuery, for example two different versions. However, at least one of them would need to use jQuery.noConflict() so that they could each be referenced. Loading two copies where the second clobbers the first doesn't make sense.
The fix is don't include jQuery twice. I don't think jQuery needs to support itself getting loaded twice.