Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1806 How would I determine if the visitor's platform is either a Mac or a Windows machine and send them to the appropriate directory on my server?

You are here: irt.org | FAQ | JavaScript | Link | Q1806 [ previous next ]

Try:

<html>
<head>
<script>
appVer = navigator.appVersion.toLowerCase();
win = (appVer.indexOf('win') !=-1)?1:0;
mac = (appVer.indexOf('mac') !=-1)?1:0;
href = window.location.href.toLowerCase();
macDir = (href.indexOf('/mac') !=-1)
currentPage = href.substring(href.lastIndexOf('/'));
if (win && macDir) window.location = '/windows'+currentPage;
else if (mac && !macDir) window.location = '/mac'+currentPage;
</script>
</head>

©2018 Martin Webb