/    Sign up×
Community /Pin to ProfileBookmark

Detect OS and Redirect

For my downloads page I want to automatically check the OS and then redirect to an alternative page. Basically if the user’s OS is Mac then redirect to a separate Mac download page, all over OS’ remain on the same page.
Perhaps JavaScript may not be the best to use in this instance.

Thanks in advanced.

Code would be appreciated indicating the file format.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@scragarAug 14.2008 — if(navigator.userAgent.indexOf('Mac') > -1){
// mac
}else if(navigator.userAgent.indexOf('Windows') > -1){
// windows
}else if(navigator.userAgent.indexOf('Linux') > -1){
// linux
}else if(navigator.userAgent.indexOf('BSD') > -1){
// BSD
}else{
// unknown, although there won't be many unknowns :P
};

this info can be spoofed, so always offer a way to go to a select the option for yourself page. Oh, and not everyone will have javascript enabled, remember that.
Copy linkTweet thisAlerts:
@EpicKrisauthorAug 14.2008 — 
this info can be spoofed, so always offer a way to go to a select the option for yourself page. Oh, and not everyone will have javascript enabled, remember that.[/QUOTE]


What do you mean this information can always be spoofed?

I understand I can use a no script tag for those who do not have JavaScript enabled, but where do I put the redirect URLs in the code above? It seems a little confusing to me as I'm not very experienced with JavaScript. ?
Copy linkTweet thisAlerts:
@felgallAug 14.2008 — Useragent is a user enterable field. Some browsers limit you to selecting the useragent from a list of two or three values all of which will identify the operating system the same way while others such as Internet Explorer and Firefox allow the browser owner to use a useragent of "eat at Joe's for the best pizza" if that is what they want their useragent to read.

Which part of "eat at Joe's for the best pizza" would you use to work out which operating system it is given that Firefox can run on all the different operating systems you are likely to want to test for (of course if it were IE using that useragent then you'd know that it was running on Windows but then you can't tell which browser it is either).

There is nothing you can put in the noscript tag that will do the redirect for you so having one is pointless in this instance.
Copy linkTweet thisAlerts:
@EpicKrisauthorAug 14.2008 — Sorry, you've completely lost me. :eek:
Copy linkTweet thisAlerts:
@rnd_meAug 14.2008 — who care's if it's "spoofed" why would anyone want to browse like that anyway?

this is not a security issue, it a minor user convenience.

i would send everyone to the windows download page first, and re-direct from there. this avoids a redirect for 91% of users.


put scragar's code from post two in a script tag in your head, and add the redirect under the condition.

for instance mac, served on a page called macdl.htm:

location.href="macdl.htm";
Copy linkTweet thisAlerts:
@scragarAug 14.2008 — who care's if it's "spoofed" why would anyone want to browse like that anyway?[/QUOTE]
sometimes it's required to even be able to get the site to treat you with any sort of respect(there was a link in the cafe some time ago with a site that blocked anything other than IE, so spoofing would be required to access said site without using IE), anything running under a compatibility layer will ID itself wrong be default anyway(wine(windows on linux), Mac-on-Linux(mac on linux, obviously), cygwin(linux/BSD on windows) - the list isn't comprehensive BTW, these are just the ones I've used).

and of course, there's the obvious reason, to protect your privacy blah, blah, blah(sorry, but I don't think this ones a legit excuse, although it get's used a lot).
Copy linkTweet thisAlerts:
@rnd_meAug 14.2008 — sometimes it's required to even be able to get the site to treat you with any sort of respect(there was a link in the cafe some time ago with a site that blocked anything other than IE, so spoofing would be required to access said site without using IE), anything running under a compatibility layer will ID itself wrong be default anyway(wine(windows on linux), Mac-on-Linux(mac on linux, obviously), cygwin(linux/BSD on windows) - the list isn't comprehensive BTW, these are just the ones I've used).

and of course, there's the obvious reason, to protect your privacy blah, blah, blah(sorry, but I don't think this ones a legit excuse, although it get's used a lot).[/QUOTE]


i was thinking more of the pizza example.

as long as there is a click between the download commencement and the page visit, i would be surprised if a cygwin or wine user couldn't figure out which one to download.


firefox provides navigator.platform which can remove any doubt for that browser's users..
Copy linkTweet thisAlerts:
@EpicKrisauthorAug 14.2008 — I think I understand what you're saying and a Windows download page as the default page which then redirects Mac users to a separate download page seems like something i'd like to achieve. It's just I still have little understanding of JavaScript. ?
×

Success!

Help @EpicKris spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...