OS判別JS

何か使えるかもしれないので、OS判別スクリプトをメモ

var getOS = function() {
   var agent = navigator.userAgent.toLowerCase() ;
   var Win_OS = agent.indexOf("win") != -1 ;
   var Mac_OS = agent.indexOf("mac") != -1 ;
   var Linux_OS = agent.indexOf("linux") != -1 ;
   var Other_OS = agent.indexOf("win") == -1 &&
   agent.indexOf("mac") == -1 &&
   agent.indexOf("linux") == -1 ;

   if(Win_OS){os = "Windows"}
   if(Mac_OS){os = "MacOS";}
   if(Linux_OS){os = "Linux";}
   if(Other_OS){os = "不明";}
   return os;
}
カテゴリー: Ajax, JavaScript   パーマリンク

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>