Browser history sniffing with Dojo
Niall Kennedy posted a now-famous article about using some browser trickery to determine what websites a user on your site has visited. I’ve taken that concept and created a module that can be used with the Dojo Toolkit javascript framework.
It provides two methods that you can use in your code, isVisited and isAnyVisited.
One important note about your URL specification is that you must specify an *exact* URL that the user has been to. So, for example, if someone has visited several twitter profiles, but never actually went to the homepage or signin screen, then it would be difficult/impossible to tell whether or not they were a twitter user without a massive brute-force query.
You can download sniff.js, or view a demo.
Sample usage:
dojo.require("mdg.sniff"); var usedYahoo = mdg.sniff.isVisited("http://www.yahoo.com"); var usedGoogleMaps = mdg.sniff.isAnyVisited([ "http://maps.google.com", "http://maps.google.com/maps"]); var usedFacebook = mdg.sniff.isAnyVisited([ "http://www.facebook.com", "http://www.facebook.com/index.php", "https://login.facebook.com/login.php"]);
Source code:
dojo.provide("mdg.sniff"); // // Browser history sniffing, based on infamous blog post: // <http://www.niallkennedy.com/blog/2008/02/browser-history-sniff.html> // // Sample usage: // // dojo.require("mdg.sniff"); // var usedYahoo = mdg.sniff.isVisited("http://www.yahoo.com"); // var usedGoogleMaps = mdg.sniff.isAnyVisited([ // "http://maps.google.com", // "http://maps.google.com/maps"]); // var usedFacebook = mdg.sniff.isAnyVisited([ // "http://www.facebook.com", // "http://www.facebook.com/index.php", // "https://login.facebook.com/login.php"]); // // Works with Dojo 1.3 and 1.4 (*may* work with 1.2 as well) // dojo.require("dojox.html.styles"); (function(){ var _this = this; this.sniffCache = {}; dojox.html.insertCssRule(".dojohistorysniff a", "color:#000000;"); dojox.html.insertCssRule(".dojohistorysniff a:visited", "color:#ff0000 !important;"); this.isAnyVisited = function(/*Array*/urls) { for (i=0; i<urls.length; i++) { if (_this.isVisited(urls[i])) { return true; } } return false; }; this.isVisited = function(/*String*/url) { if (typeof(_this.sniffCache[url]) != 'undefined') { return _this.sniffCache[url]; } var link = _this.addLink(url); var color = new dojo.Color(dojo.style(link, "color")); if (color.r == 255) { _this.sniffCache[url] = true; return true; } _this.sniffCache[url] = false; return false; }; this.insertSniffDiv = function() { return dojo.create("div", {className: "dojohistorysniff"}, dojo.body()); }; this.getSniffDiv = function() { var divs = dojo.query("div.dojohistorysniff"); if (divs.length > 0) { return divs[0]; } return _this.insertSniffDiv(); }; this.addLink = function(/*String*/url) { var div = _this.getSniffDiv(); return dojo.create("a", {href: url}, div); }; /** * mdg.sniff.isVisited * Check whether or not a URL has been visited * @param url String * @return boolean */ mdg.sniff.isVisited = this.isVisited; /** * mdg.sniff.isAnyVisited * Check whether or not *any* of the URLs specified have been visited * @param urls Array of Strings * @return boolean */ mdg.sniff.isAnyVisited = this.isAnyVisited; })();
- Filed under software development
- Tagged with css, dojo, javascript, tips & tricks
- Comments(13)

August 2nd, 2010 at 9:47 pm
Will definitely be trialling the script as above. Thanks for sharing Mike.
August 5th, 2010 at 11:20 am
This does not work in Safari 5.0.
February 6th, 2011 at 4:12 pm
Just following up to Alex’s post, how come this works on most browsers but not Safari?
September 28th, 2012 at 4:54 pm
faxless payday loans – faxless payday loans , http://quickfaxlesspaydayloanonline.com/#15222 payday loan online
September 28th, 2012 at 6:55 pm
generique viagra – viagra en ligne , http://acheterviagraenlignefr.com/#15830 acheter viagra en ligne
September 29th, 2012 at 6:17 am
Shelf Life Levitra Online Pharmacy Viagra On Prescription In The University Of Kentucky Celecoxib Generic Medications Discount Pharmacy Cialis Viagra On Nhs Prescription Public Prescription Services Soma Methotrexate In Psoriasis Liver Damage Prozac Clinical Trial Obsessive Compulsive Disorder How Long To Get Hooked On Prozac Atarax Pfizer Pregnant Mouse Soma No Rx Overnight Delivery buy adipex without rx How Do Ativan Make You Feel Viagra Negative Risks Xanax Patient Information Ultram Pain Releiver buy klonopin online cheap Furosemide Javma Singulair Q Var Amoxicillin And Advil Together Amoxicillin Trihydrate Depression No Prescription Buy Cheap Soma Cialis In Usa Discount Soma 375 Mg Soma Delivery Culture Amoxicillin Dose Dogs Buy Singulair No Prescription Shipping Uses Of Alprazolam Borderline Personality Disorder Lorazepam R59 Round White Pill Soma Drug Risks Ultram Er Police Viagra And Extacy Cialis Levitra
October 16th, 2012 at 4:48 am
Hello! dkdbaea interesting dkdbaea site! I’m really like it! Very, very dkdbaea good!
November 14th, 2012 at 1:18 am
cppgcnjlf.hsjggjui, Buy ativan chat room, aCEPysA, [url=http://www.bigboysandtheirtoys.com/ativan.html]Buy ativan online 32[/url], eSVtpNM, http://www.bigboysandtheirtoys.com/ativan.html Where to buy ativan, WkjtJGl.
November 29th, 2012 at 4:49 pm
+- levitra no prescription
– levitra online no prescription
http://buylevitraonlinetoday.com/#79800 — generic levitra no prescription
February 23rd, 2013 at 4:43 pm
pbeknnjlf.hsjggjui, How much ativan used to make someone comotose, oEevLGf, [url=http://ativanknowledgebase.com/]How long is ativan in the body[/url], oemFtot, http://ativanknowledgebase.com/ How much ativan used to make someone comotose, nPRCWbd.
April 9th, 2013 at 10:47 pm
topcunjlf.hsjggjui, Cialis levitra staxyn stendra and viagra, DIlNyMF, [url=http://stendra365.com/]Stendra[/url], JcWWScs, http://stendra365.com/ Stendra, EKGKuZo.
May 31st, 2013 at 12:05 am
Another type of comparison you could want to create is if the
cash advance lender allows extensions or renewals and how often times they permit you to accomplish this.
These options are not meant to get long-term solutions because their interest levels less difficult higher along with the loan amounts are
normally under one thousand dollars.
June 17th, 2013 at 9:18 pm
Having read this I believed it was rather enlightening.
I appreciate you taking the time and energy to put this article together.
I once again find myself spending a significant amount of time both reading and commenting.
But so what, it was still worthwhile!