You can find browser, mobile or operating system(OS) specific javascript code snippets in this section.

browser-hack,snippets

2014-11-13 • JQuery, Snippets • Views: 1309

Browser and Version

 

  • Mozilla Firefox

if( $.browser.mozilla ){
alert("mozilla Firefox");
}

  • Monzilla Firefox and Version

if ($.browser.mozilla && $.browser.version >= "1.8" ){
alert("Monzilla Firefox >= version 1.8");
}

 

  • Safari (Only Safari)

if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1){
alert('Its Safari');
}

 

  • Chrome and Opera

$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
if ($.browser.chrome) {
alert("Chrome");
}

 

  • Internet Explorer

if ($.browser.msie){
alert("İnternet Explorer");
}

 

  • Internet Explorer and version

if ($.browser.msie && $.browser.version <= 6 ){
alert("İnternet Explorer <= version 6");
}

 

Operating System(OS)

 

  • Windows

if (navigator.appVersion.indexOf("Win") != -1){
alert("Windows");
}

 

  • MacOS

if (navigator.appVersion.indexOf("Mac") != -1){
alert("MacOS");
}

 

  • UNIX

if (navigator.appVersion.indexOf("X11") != -1){
alert("UNIX");
}

 

  • Linux

if (navigator.appVersion.indexOf("Linux") != -1){
alert("Linux");
}

Mobile

 

  •  iPhone

if(navigator.userAgent.match(/iPhone/i)){
alert("iPhone");
}

 

  • Android

if(navigator.userAgent.match(/Android/i)){
alert("Android");
}

 

  • iPod

if(navigator.userAgent.match(/iPod/i)){
alert("iPod");
}

 

  • iPad

if(navigator.userAgent.match(/iPad/i)){
alert("iPad");
}

 

  • webOS

if(navigator.userAgent.match(/webOS/i)){
alert("webOS");
}

 

  • BlackBerry

if(navigator.userAgent.match(/BlackBerry/i)){
alert("BlackBerry");
}

 

  • Windows Phone

if(navigator.userAgent.match(/Windows Phone/i)){
alert("Windows Phone");
}

 

  • full mobile

if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
alert("mobile");
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Shares