neoprolog

Browser check with a different way

While the www technologies going smarter, much more easier, development techniques too goes smarter, smaller, bright&brilliant in a mathematical way. Day after day, we forgetting the old-style development techniques replacing with the new ways.

Although huge percentage of developers don’t need browser check, sometimes it requires to be used. Then I think that this way of browser checking could help some developers about detecting the browsers.

The Script

This script uses Mike Brittain’s inArray prototype script.

<script type="text/javascript">
var is = {
ua: navigator.userAgent.toLowerCase(),
tArray: [],
fArray: [],
browser: function (trueArray, falseArray) {
this.tArray.length=0;
this.fArray.length=0;
for (var i=0; i<truearray .length; i++) {
this.ua.search(trueArray[i])!=-1 ? this.tArray.push(1) : this.tArray.push(0);
}
for (var j=0; j<falseArray.length; j++) {
this.ua.search(falseArray[j])==-1 ? this.fArray.push(0) : this.fArray.push(1);
}
return ((this.tArray.inArray(0) ? 0 : 1) && (this.fArray.inArray(0) ? 1 : 0));
},
debug:function(){
return this.ua;
}
}

/* http://code.mikebrittain.com/2006/01/inarray-method-for-javascript-and-actionscript/ */
Array.prototype.inArray =function(value){
var i;
for(i=0;i<this.length;i++){
if(this[i]===value) return true;
}
return false;
};
</script>

Usage

General usage looks likes:


is.browser([true Conditions], [false Conditions]);

Firefox 2.0 check


if(is.browser(['firefox', 'gecko', 'firefox/2.0'] , ['windowsszz', 'webtv'])) {
alert(’firefox 2.0′)
}

Internet Explorer check (any)


// Because Internet Explorer doesn't run on linux
// Same way (is.browser(['safari'] , ['linux'])) will select all safari versions
if(is.browser(['msie'] , ['linux'])) {
alert(’any msie’);
}

Selecting Opera 7 or 8


// 'sdfg' figures any wrong string, because Opera runs on linux, windows and mac
if(is.browser(['opera', '7.0'] , ['sdfg']) || is.browser(['opera', '8.0'] , ['sdfg'])) {
alert(’Opera 7 or 8′);
}

if you don’t sure about browser specific keywords, use “alert(is.debug());” and use keywords from the debug string for true conditions

alert(is.debug());

Note:Please report bugs and new recommendations

Browser check Script (ZIP) - Download

Comments: 0


Comments

No comments.

RSS feed for comments on this post. TrackBack URI

Add Comment

 

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strike> <strong>


  • Bloguma Dokunma!

    www.sansuresansur.org

  • About

    Neoprolog Özgür Odabaşı’nın web teknolojileri blogudur.
    Neoprolog is Özgür Odabasi’s web technologies blog.
    devamı...

  • Kara-kara kategori bulutları

    Opensource (Açık Kaynak) Internet Development (Geliştirme) Apple Web 2.0 Mac OS X Linux Genel *N*X Design (Tasarım) Tools Python XHTML Sosyal Microsoft MacOsX10.5 Accessibility (Erişilebilirlik) Capital (Kapital) Economy (Ekonomi) W3C Browsers (Tarayıcılar) Apache Usability (Kullanılırlık) Rails Ruby PHP Navigation (Navigasyon) Google CSS AJAX Adobe Javascript Debugging (Hata Ayıklama) Internet Explorer Inspiration (Esin) Actionscript Sanat (Art) Veri İşleme (Data Processing) Creative Commons neoprolog .NET Görsel Tasarım Textmate Security (Güvenlik) Themes (Temalar) Ubuntu Korsan ColdFusion bienal AIR Flex Motion (Animasyon) Protesto Project Management (Proje Yönetimi) OpenLazslo Subversion

  • Liste-liste kategoriler

  • Arşiv

  • Son Eklenenler

  • Son Yorumlar

  • Meta

  • Hala üzerimde bluzun...

    1. cd cover
    2. cd cover
    3. cd cover
    4. cd cover
    5. cd cover
    6. cd cover
    7. cd cover
    8. cd cover
    9. cd cover
    10. cd cover
    11. cd cover
    12. cd cover
    13. cd cover
    14. cd cover
    15. cd cover
    16. cd cover
    17. cd cover
    18. cd cover
    19. cd cover
    20. cd cover
    21. cd cover
    22. cd cover
    23. cd cover
    24. cd cover
    25. cd cover
    26. cd cover
    27. cd cover
    28. cd cover
    29. cd cover
    30. cd cover


  • Spreadfirefox Affiliate Button
  •