Detecting Mac OS X (When feature detection doesn't work?)

P

petermichaux

Hi,

I don't know if there is a way to feature detect for this or not. I
have a list and the user can click on items to select. I would like
that they can command-click on Mac or control-click on other OS to
multiple select. This matches normal file system behavior.

I found this example which doesn't seem to work in Opera on Mac: the
mac variable will be false.

var mac = (navigator.appVersion.indexOf("Mac")!==-1) ? true : false;

if (mac && e.metaKey) || (!mac && e.ctrlKey) {
// do multiple selection
}

So is there a way to feature detect for what I'm doing?

Is there a reliable way to know if the OS is Mac or not?

Thanks,
Peter
 
R

Randy Webb

(e-mail address removed) said the following on 7/30/2006 1:24 PM:
Hi,

I don't know if there is a way to feature detect for this or not. I
have a list and the user can click on items to select. I would like
that they can command-click on Mac or control-click on other OS to
multiple select. This matches normal file system behavior.

I found this example which doesn't seem to work in Opera on Mac: the
mac variable will be false.

var mac = (navigator.appVersion.indexOf("Mac")!==-1) ? true : false;

What does the navigator.appVersion give for Opera on the Mac? It could
be nothing more than a lowercase m versus uppercase M.
if (mac && e.metaKey) || (!mac && e.ctrlKey) {
// do multiple selection
}

So is there a way to feature detect for what I'm doing?

What you are doing above is not "feature detecting" though, it is OS
detection based on your "mac" variable. What happens if you drop the OS
code all together?

if (e.metaKey || e.ctrlKey){

}
Is there a reliable way to know if the OS is Mac or not?

Not if your method is based on the navigator object and it's spoof-able
properties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top