Note that there are some explanatory texts on larger screens.

plurals
  1. POI am able to detect browsing, but I want additional information
    primarykey
    data
    text
    <p>I'm making a kind of Browser Detection library (I know user agent sniffing isn't ideal). I found a pretty useful snippet on quirksmode.org that looked something like this:</p> <pre><code>var $browser = { init: function () { this.name = this.searchString(this.dataName) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; }, searchString: function (data) { for (var i=0;i&lt;data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) { return data[i].identity; } } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataName: [ { string: navigator.userAgent, subString: "Chrome", identity: "Chrome" }, { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version" }, { prop: window.opera, identity: "Opera", versionSearch: "Version" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { // for newer Netscapes (6+) string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Internet Explorer", versionSearch: "MSIE" }, { // for older Netscapes (4-) string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" } ] }; $browser.init(); </code></pre> <p>So now I can do something like</p> <pre><code>alert($browser.name + $browser.version); </code></pre> <p>But I also want to be able to do $browser.author, $browser.prefix and $browser.engine. Anyone know how I could do this? I know I could do </p> <pre><code> if($browser.name == "Chrome"){ var engine = "WebKit" } </code></pre> <p>But I don't want just "engine", I want "$browser.engine"</p> <p><b><h2>EDIT</h2></b> Ok, look guys, as I said before <strong>I know user agent sniffing isn't ideal</strong>. And I'm not basing my entire project on this. This is just a short little module on a bigger JS file. This is just a handy $browser module. I know feature detection is <b>way</b> better than ua sniffing, and I use modernizr way more than I do jQuery browser object, or Dojo "has". In fact I never use those. And I know that stackoverflow typically isn't a tutoring website (well, isn't a tutoring website rather), but I was kinda hoping just to find out a quick little way to add extra information in each object manually. I've tried many ways and kept getting errors or fails. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload