JS library detector

Ever wondered which JavaScript library (if any) is hidden beneath the bells & whistles of each site you gazed at? Since I am a curious person, I find myself wondering every time, so after a bit of research, I wrapped up a little bookmarklet that in…


This content originally appeared on Lea Verou’s blog and was authored by Lea Verou

Ever wondered which JavaScript library (if any) is hidden beneath the bells & whistles of each site you gazed at? Since I am a curious person, I find myself wondering every time, so after a bit of research, I wrapped up a little bookmarklet that instantly told me the answer every time.

The logic behind it is that every JavaScript library creates at least one global variable with an easily recognizable name. For most JavaScript libraries, this is simply their name (Prototype, jQuery, DOMAssistant, MooTools, dojo). For some others, its something close enough to their name (YAHOO for YUI, Scriptaculous for script.aculo.us, Ext for ExtJS). So if you check the precence of this global variable, you are effectively checking for the precence of the related framework. Most of them also contain a property with their version (which is usually named ‘version’ or ‘Version’ or ‘VERSION’ (in YUI)) - in fact the only library that did not contain such a property was DOMAssistant. So, after a sneak peek at their code, I could easily set up some conditionals that check whether a certain library exists in the page and if so, alert its name and version. If multiple libraries exist at the same page, multiple popups will appear.

So, here is the bookmarklet:

JS library detector

Just drag it to your bookmarks toolbar and it’s ready.

And here is the human-readable code:

if('Prototype' in window)
{
	var ret = 'Prototype ' + Prototype.Version;
	if('Scriptaculous' in window) ret += ' with script.aculo.us ' + Scriptaculous.Version;
	alert(ret);
}
if('jQuery' in window) alert('jQuery ' + jQuery.fn.jquery);
if('MooTools' in window) alert('MooTools ' + MooTools.version);
if('YAHOO' in window) alert('YUI ' + YAHOO.VERSION);
if('dojo' in window) alert('Dojo ' + dojo.version);
if('Ext' in window) alert('ExtJS ' + Ext.version);
if('DOMAssistant' in window) alert('DOMAssistant');

Am I nuts? Certainly. Has it been useful to me? Absolutely.


This content originally appeared on Lea Verou’s blog and was authored by Lea Verou


Print Share Comment Cite Upload Translate Updates
APA

Lea Verou | Sciencx (2009-02-11T00:00:00+00:00) JS library detector. Retrieved from https://www.scien.cx/2009/02/11/js-library-detector/

MLA
" » JS library detector." Lea Verou | Sciencx - Wednesday February 11, 2009, https://www.scien.cx/2009/02/11/js-library-detector/
HARVARD
Lea Verou | Sciencx Wednesday February 11, 2009 » JS library detector., viewed ,<https://www.scien.cx/2009/02/11/js-library-detector/>
VANCOUVER
Lea Verou | Sciencx - » JS library detector. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2009/02/11/js-library-detector/
CHICAGO
" » JS library detector." Lea Verou | Sciencx - Accessed . https://www.scien.cx/2009/02/11/js-library-detector/
IEEE
" » JS library detector." Lea Verou | Sciencx [Online]. Available: https://www.scien.cx/2009/02/11/js-library-detector/. [Accessed: ]
rf:citation
» JS library detector | Lea Verou | Sciencx | https://www.scien.cx/2009/02/11/js-library-detector/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.