Skip to content

Instantly share code, notes, and snippets.

@kawabataryo
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawabataryo/d5feff4b65cf668a699e to your computer and use it in GitHub Desktop.
Save kawabataryo/d5feff4b65cf668a699e to your computer and use it in GitHub Desktop.
ユーザーエージェントを判定
function DecideUA(){
this.name = window.navigator.userAgent.toLowerCase();
}
DecideUA.prototype = {
/**
* @param {Strihg} str 判定するデバイスのユニークな文字列
* @return {Boolean}
*/
match: function(str){
return (this.name.indexOf(str) !== -1);
}
}
@kawabataryo
Copy link
Author

//init
var ua = new DecideUA();

if(ua.match('iphone')){
    console.log('This is iPhone.');
}else if(ua.match('android')){
    console.log('This is Android.');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment