Click to See Complete Forum and Search --> : Speed of try..catch?
virtuald
08-19-2006, 01:49 PM
Hey, on my website (http://www.virtualroadside.com), I'm modifying the way the cursor looks as part of a game on there.. and I noticed that in IE5 it doesn't support setting the cursor to 'pointer', and that you need to use 'hand' instead. My solution for it was this:
try{
o.style.cursor = 'pointer';
}catch(e){
o.style.cursor = 'hand';
}
But it kind of bugs me because of in all the other languages I've used, exceptions tend to be really slow, and I've never liked them all that much anyways. Is there any other way to detect what types of pointers the browser supports? Thanks.
Kravvitz
08-19-2006, 06:26 PM
You should use object detection to detect IE. I don't think your code would work anyway because it will just ignore the value if it doesn't understand it; it won't throw an error.
var isIE = (document.defaultCharset && !window.home);
if(isIE) o.style.cursor = 'hand';
else o.style.cursor = 'pointer';
virtuald
08-19-2006, 06:28 PM
Well actually, the code does work because oddly enough IE throws an exception. IE6 does support the 'pointer' value, so I'm not sure a generic object detect would be the best idea here. :-/ I was hoping maybe a more specific object detection for that value, but it probably doesn't exist..
Kravvitz
08-19-2006, 06:45 PM
Really? Odd.
IE6 supports both. So why does it matter?
There is no object to detect for this. You have to use other known objects for the browsers with this known incompatibility.
You could use this instead:
var IE4or5 = (document.defaultCharset && !window.home &&
!document.compatMode)?1:0;
Orc Scorcher
08-20-2006, 03:35 AM
You could simply use this exception once to detect whether the browser supports "pointer", set a variable accordingly and then use that.
A1ien51
08-20-2006, 08:51 AM
How about avoiding all of this and set a CSS class/rule that has
.point{cursor:pointer,hand;}
and set the className to it?
And you really care about IE 5 back on windows 98 machines? lol
Eric
Kravvitz
08-20-2006, 02:50 PM
A1ien51, cursor can't take a comma separated list of the normal cursors like that.
You could write it like this.
.point{cursor:pointer;cursor:hand;}
You could simply use this exception once to detect whether the browser supports "pointer", set a variable accordingly and then use that.
Perhaps he doesn't want to write the extra code needed to shave a few milliseconds off or doesn't want to use a global variable to do this.