JavaScript DHTML/Development/System Properties
Версия от 10:02, 26 мая 2010; (обсуждение)
Get user"s operating system information
<html>
<head>
<script type="text/javascript">
function yourOS() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("win") != -1) {
return "Windows";
} else if (ua.indexOf("mac") != -1) {
return "Macintosh";
} else if (ua.indexOf("linux") != -1) {
return "Linux";
} else if (ua.indexOf("x11") != -1) {
return "Unix";
} else {
return "Computers";
}
}
</script>
<body>
<h1>Welcome to GiantCo Computers</h2>
<h2>We love
<script type="text/javascript">document.write(yourOS())</script>
<noscript>Computers</noscript>
Users!</h2>
</body>
</html>
OS (Operating system) name
<!--
Example File From "JavaScript and DHTML Cookbook"
Published by O"Reilly & Associates
Copyright 2003 Danny Goodman
-->
var isWin = (navigator.userAgent.indexOf("Win") != -1);
var isMac = (navigator.userAgent.indexOf("Mac") != -1);
var isUnix = (navigator.userAgent.indexOf("X11") != -1);
----------
<script language="JavaScript" type="text/javascript">
document.write("<style type="text/css">");
document.write("body {font-size:" + ((isMac) ? "12" : "10") + "pt}");
document.write("</style>");
</script>