View Full Version : doubleClick not working in IE (FIXED THANKS TO Pyth007)
rlemon
11-01-2005, 03:04 PM
http://rlemon.com/l-pic/ is the site.
To See:
1) enter http://rlemon.com/l-pic/ in IE
2) single click on a folder
*Notice the hi-lighting
3) double click on the same folder
*nothing happens
4) enter the same page with Moz, FF, or NS and double click on a folder.
*you enter the folder
here is the section of code. (note, the site is in three frames, the main page (frame named 'main') is where the javascript is.
var cc=0
var to;
var onE;
document.onclick=function(){ Set_Count('null', 'null', 'null', 'null', 'null'); onE=false; }
function Set_Count(id, desc, loc, frame, obj){
if (obj!='null'){
clearTimeout(to);
cc++; // increase Count value by 1
to=setTimeout(function(){Check_Count(id, desc, loc, frame);},300);
onE=true;
}
if (!onE){
unHLElement();
}
}
function Check_Count(id, desc, loc, frame){
if(cc==1){
click1(id, desc);
}
if(cc==2){
alert('Event: dblClick;');
click2(loc, frame);
}
cc=0; // reset Count value
}
function click1(id, desc){
HLElement(id, desc);
}
function click2(loc, frame){
gotoLoc(loc, frame);
}
Pyth007
11-01-2005, 04:01 PM
Maybe try using onDoubleClick... I know that works for IE, not sure about others, though...
EDIT: err.... should be ondblclick... Also if you were wanting to try doing different things for a click vs. double-click, this site (http://www.chipchapin.com/WebTools/JavaScript/example3-01.html)has a work-around, although I've been told that a "lazy" double click might get picked up as both (maybe play around with the parameters...)
rlemon
11-01-2005, 05:35 PM
Maybe try using onDoubleClick... I know that works for IE, not sure about others, though...
EDIT: err.... should be ondblclick... Also if you were wanting to try doing different things for a click vs. double-click, this site (http://www.chipchapin.com/WebTools/JavaScript/example3-01.html)has a work-around, although I've been told that a "lazy" double click might get picked up as both (maybe play around with the parameters...)
ondblclick wont work
order of events:
onMouseDown
onClick
onMouseUp
onMouseDown
onDblClick
onMouseUp
so as you can see there is no possible way to use onClick and onDblClick on the same element.
rlemon
11-01-2005, 09:29 PM
The way i have done it,
as you can see above
is onClick increment the variable 'cc' and start the timeout for the click check.
if you click on the element again after the timeout is started cc increments
the function the timeout calls simply says
if(cc == 1){
do this
}
if(cc == 2){
do this
}
what i am going to try is
if(cc == 1){
} else if(cc >= 2){
}
cc = 0;
return;
rlemon
11-01-2005, 11:30 PM
Ok,
the problem is it requires 3 clicks in IE to read as two clicks.
after each click i print out on the page what the clickcount variable is.
click1 = 1
click2 = 1
click3 = 2
i don't know how to get around this, any help?
here is all the js i'm working with (there is some php in there too, hope you don't mind)
also, i know alot of this is sloppy or incorrect but it works for all intended purposes and i do plan on cleaning it up..
if(document.all){ var ct = 400; } else { var ct = 300; }
var cc=0;
var to;
var onE;
document.onclick=function(){ Set_Count('null', 'null', 'null', 'null', 'null'); onE=false; }
function test(id, c){
var e = document.getElementById(id);
e.style.padding = "0px";
e.style.border = "2px solid " + c;
}
function Set_Count(id, desc, loc, frame, obj){
if( (id != 'null') && (desc != 'null') && (loc != 'null') && (frame != 'null') ){
if (obj!='null'){
clearTimeout(to);
cc++; // increase Count value by 1
var d = document.getElementById('test');
d.innerHTML = cc;
/* test */ if(cc == 1){ var c = 'red'; } else { var c = 'green'; }
test(id, c);
to=setTimeout(function(){Check_Count(id, desc, loc, frame);},ct);
onE=true;
}
}
if (!onE){
unHLElement();
}
}
function Check_Count(id, desc, loc, frame){
if(cc==1){
HLElement(id, desc);
} else if(cc==2){
test(id, 'blue');
//gotoLoc(loc, frame);
}
cc=0; // reset Count value
}
function setView(view){
var MyUrl = new String(parent.frames['main'].location.href);
var queryString = MyUrl.split('?');
var vars = queryString[1].split('&');
var myVar = new Array();
var set = 0;
for(i = 0; i < vars.length; i++){
var tempVar = vars[i].split('=');
myVar[i] = new Array(2);
if( tempVar[0] == 'view' ){
myVar[i][0] = tempVar[0];
myVar[i][1] = view;
set = 1;
} else {
myVar[i][0] = tempVar[0];
myVar[i][1] = tempVar[1];
}
}
var newUrl = '?';
for(j = 0; j < myVar.length; j++){
newUrl+=myVar[j][0]+"="+myVar[j][1];
if(j != myVar.length-1){ // last element.
newUrl+="&";
}
}
if(set == 0){
newUrl+="&view="+view;
}
var url = queryString[0] + newUrl;
gotoLoc(url,'main');
}
function HLElement(id, desc){
unHLElement();
//clearTimeout(cto);
//clearDetails(id);
var e = document.getElementById(id);
e.style.padding = "0px";
e.style.border = "2px solid #A7BE86";
parent.frames['left_side'].setInnerHTML('jar_body_Details',desc);
}
function unHLElement(){
<?
// get the total number of folders.
$fc = 0;
$FileHandle=opendir($IMG_DIR);
while ( false !== ($folder = readdir($FileHandle))) {
if( (is_dir($IMG_DIR.$folder)) && ($folder != '.') && ($folder != '..')) { // Filter out the '.' and '..' entrys
$fc++;
}
}
?>
for(i=0;i<<? print $fc; ?>;i++){
var id = "fol"+i;
var e = document.getElementById(id);
e.style.border = "1px solid #ccc";
e.style.padding = "1px";
}
parent.frames['left_side'].setInnerHTML('jar_body_Details','<? print $detailsStart; ?>');
}
function gotoLoc(url, frame){
parent.frames[frame].location = url;
}
Pyth007
11-01-2005, 11:40 PM
I don't mean to heap it on, but I found another bug... You can get a "double click" by clicking on each folder rapidly (eg click canoe then click wedding within .3 sec.) This actually works for both browsers (so maybe this might tell us something about what's happening)!
rlemon
11-02-2005, 12:03 AM
thats because i do not force it to be the same object. i just say if object then cc++
the last object passed will be the one affected correct?
Pyth007
11-02-2005, 12:44 PM
Yeah, it causes the second folder you click to be "double clicked". As far as why IE would require a check for 3 clicks, I have a few of punts-in-the-dark:
1) Event propagation is causing the onClick to be triggered twice. I thought that the document's onClick might be doing this, but if so, it would seem that your if-statements should be catching it, since it passes 'null'...
2) IE reognizes some other event and, not finding an appropriate function to catch it, gets caught by onClick instead. Eg onMouseUp and onMouseDown may both trigger onClick instead
3) (most likely possability) IE has double-click events trigger click handlers as well as double-click handlers. Eg if ondblclick is inherited from onclick, then the double-click event might "filter up" to onclick, triggering it for the third time (twice for the actual clicks and once for "double-click"). From MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclassdoubleclicktopic.asp):
The Click event is raised every time a control is double-clicked. For example, if you have an event-handling methods for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called.
However the very next sentence contradicts this idea for three clicks being caught:
If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.
unless, of course, they mean that the Click event is caught twice for the second actual click...
rlemon
11-02-2005, 12:52 PM
go to http://www.rlemon.com/l-pic/ in ie and watch the numbers.
click = 1
click click = 1
click click click = 2
rlemon
11-02-2005, 03:56 PM
I'm bumping this with a little more specific information:
1) the problem is IE specific and is limited to the fact that it requires three clicks to act as two clicks.
1.1) The code that reads the clicks is as follows:
Element You are Clicking on (this is only the table tag for that element. I'm including all of the php surrounding it just incase there is a problem there for some reason:
$output.= '<table id="fol'.$id.'" background="'.$ROOT.'/res/img/folder.gif" style="width: 98px; height: 98px; border:1px solid #ccc; cursor: pointer;" cellpadding="0" cellspacing="0" onClick="Set_Count(this.id, \''.$description.'\', \'gallery.php?folder='.$folder.'\', \'main\')">';
and here is the JS that receives these clicks.
(again, i'm including all of the JS on the page so you can see the other functions this is interacting with. Note, I have alot of debug code in here because i've been activly trying to figure out whats going on.)
<script language="JavaScript" type="text/javascript">
if(document.all){ var ct = 400; } else { var ct = 300; }
var cc=0;
cc++;
cc--;
var to;
var onE;
document.onclick=function(){ Set_Count('null', 'null', 'null', 'null', 'null'); onE=false; }
function test(id, c){
var e = document.getElementById(id);
e.style.padding = "0px";
e.style.border = "2px solid " + c;
}
function Set_Count(id, desc, loc, frame, obj){
if( (id != 'null') && (desc != 'null') && (loc != 'null') && (frame != 'null') ){
if (obj!='null'){
clearTimeout(to);
cc++; // increase Count value by 1
if(document.all){cc++;}
var d = document.getElementById('test');
d.innerHTML = cc;
/* test */ if(cc == 1){ var c = 'red'; } else { var c = 'green'; }
test(id, c);
to=setTimeout(function(){Check_Count(id, desc, loc, frame);},ct);
onE=true;
}
}
if (!onE){
unHLElement();
}
}
function Check_Count(id, desc, loc, frame){
if(cc==1){
HLElement(id, desc);
} else if(cc==2){
test(id, 'blue');
//gotoLoc(loc, frame);
}
cc=0; // reset Count value
}
function setView(view){
var MyUrl = new String(parent.frames['main'].location.href);
var queryString = MyUrl.split('?');
var vars = queryString[1].split('&');
var myVar = new Array();
var set = 0;
for(i = 0; i < vars.length; i++){
var tempVar = vars[i].split('=');
myVar[i] = new Array(2);
if( tempVar[0] == 'view' ){
myVar[i][0] = tempVar[0];
myVar[i][1] = view;
set = 1;
} else {
myVar[i][0] = tempVar[0];
myVar[i][1] = tempVar[1];
}
}
var newUrl = '?';
for(j = 0; j < myVar.length; j++){
newUrl+=myVar[j][0]+"="+myVar[j][1];
if(j != myVar.length-1){ // last element.
newUrl+="&";
}
}
if(set == 0){
newUrl+="&view="+view;
}
var url = queryString[0] + newUrl;
gotoLoc(url,'main');
}
function HLElement(id, desc){
unHLElement();
//clearTimeout(cto);
//clearDetails(id);
var e = document.getElementById(id);
e.style.padding = "0px";
e.style.border = "2px solid #A7BE86";
parent.frames['left_side'].setInnerHTML('jar_body_Details',desc);
}
function unHLElement(){
<?
// get the total number of folders.
$fc = 0;
$FileHandle=opendir($IMG_DIR);
while ( false !== ($folder = readdir($FileHandle))) {
if( (is_dir($IMG_DIR.$folder)) && ($folder != '.') && ($folder != '..')) { // Filter out the '.' and '..' entrys
$fc++;
}
}
?>
for(i=0;i<<? print $fc; ?>;i++){
var id = "fol"+i;
var e = document.getElementById(id);
e.style.border = "1px solid #ccc";
e.style.padding = "1px";
}
parent.frames['left_side'].setInnerHTML('jar_body_Details','<? print $detailsStart; ?>');
}
function gotoLoc(url, frame){
parent.frames[frame].location = url;
}
/*function clearDetails(id){
cto = window.setTimeout(function(){ unHLElement(id); }, 60000);
}*/
</script>
Now, if you visit http://www.rlemon.com/l-pic/ you will see there are some broken folders there.
in IE if you single click on a folder, the border color of that element will turn red for .3 seconds then revert to green.
in IE if you double click it will act as a single click and the border will go red then back to green.
on each click i have also updated a span with the current click count (var cc)
in IE it breaks down like so:
click once -> cc = 1;
click twice-> cc = 1;
click three times-> cc = 2;
click repetitivly after that leaving less than .3 seconds between each click and CC will increment normally.
in FF(my main browser) it breaks down like so:
click once -> cc = 1;
click twice-> cc = 2;
click three times-> cc = 3;
click repetitivly after that leaving less than .3 seconds between each click and CC will increment normally.
I have no clue why this isn't working. I've tried doing some crazey things for IE and none have worked. if anyone can please look into this and give me a hang i would appreciate it.
minimally could someone help me narrow down the problem to some specific code.. i have no trouble fixing it... i still don't really understand why its happening though.
Pyth007
11-02-2005, 07:42 PM
Sorry about those last guesses; I misunderstood what you meant about the 3 clicks...
So ready for a new guess?
In IE, many extra attributes are set, even with null values. To see this, run this short page in both IE and Firefox:
<html><head>
<script>
function showAtribs()
{
var linknode=document.getElementById('linkNode');
var linkattributes=linknode.attributes;
for(var counter=0; counter<linkattributes.length; counter++)
{
document.getElementById('report').appendChild(document.createTextNode(linkattributes[counter].nodeName+" is "+linkattributes[counter].nodeValue));
document.getElementById('report').appendChild(document.createElement('br'));
}
}
</script>
</head><body onLoad="showAtribs()">
<a href="#" id="linkNode">Click here</a>
<div id='report' style="width:500; height:500; border:1"></div>
</body></html>
As you can see, ondblclick is in the IE list, but not in the Firefox list. Thus the second click in the double-click may be caught as a double-click, but just doesn't do anything. Maybe try adding an ondblclick handler that also calls your Set_Count(); other browsers would just run this an extra time, which shouldn't hurt if Check_Count() looks for 2 or more clicks, and IE will (I think) run it twice, once thru click and once thru dblclick.
rlemon
11-02-2005, 08:23 PM
one further thing i noticed.
i have set the timeout in IE to 1 second.
after the initial click, while the timeout is running, if i dbl click i get it.
coudl this mean something? maybe not? maybe so....
check out http://www.rlemon.com/l-pic/
rlemon
11-02-2005, 09:19 PM
Sorry about those last guesses; I misunderstood what you meant about the 3 clicks...
So ready for a new guess?
In IE, many extra attributes are set, even with null values. To see this, run this short page in both IE and Firefox:
<html><head>
<script>
function showAtribs()
{
var linknode=document.getElementById('linkNode');
var linkattributes=linknode.attributes;
for(var counter=0; counter<linkattributes.length; counter++)
{
document.getElementById('report').appendChild(document.createTextNode(linkattributes[counter].nodeName+" is "+linkattributes[counter].nodeValue));
document.getElementById('report').appendChild(document.createElement('br'));
}
}
</script>
</head><body onLoad="showAtribs()">
<a href="#" id="linkNode">Click here</a>
<div id='report' style="width:500; height:500; border:1"></div>
</body></html>
As you can see, ondblclick is in the IE list, but not in the Firefox list. Thus the second click in the double-click may be caught as a double-click, but just doesn't do anything. Maybe try adding an ondblclick handler that also calls your Set_Count(); other browsers would just run this an extra time, which shouldn't hurt if Check_Count() looks for 2 or more clicks, and IE will (I think) run it twice, once thru click and once thru dblclick.
thankyou very much Pyth007, that seemed to fix things up.
I was almost at my end with this too..... two days trying to figure it out.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.