December 12, 200916 yr Have asked this on the 'how do I do that?' board. View the thread here: http://www.webdesignerforum.co.uk/topic/29749-target-a-pc-with-csshtml/. Basically I want to detect the operation system and redirect if it is windows, and do nothing (stay on the homepage) if mac. I found this code below that detects the OS but have no idea about javascript and how to change it to redirect code. Can anyone help? // This script sets OSName variable as follows: // "Windows" for all versions of Windows // "MacOS" for all versions of Macintosh OS // "Linux" for all versions of Linux // "UNIX" for all other UNIX flavors // "Unknown OS" indicates failure to detect the OS var OSName="Unknown OS"; if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; document.write('Your OS: '+OSName);
December 15, 200916 yr // This script sets OSName variable as follows: // "Windows" for all versions of Windows // "MacOS" for all versions of Macintosh OS // "Linux" for all versions of Linux // "UNIX" for all other UNIX flavors // "Unknown OS" indicates failure to detect the OS var OSName="Unknown OS"; if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; if (OSName == "Windows") { window.location = "http://www.yoururl.com" }; Try this. I don't do much vanilla javascript, just jQuery. But try it and see if it works.
Create an account or sign in to comment