Browser history sniffing with Dojo

Posted by Mike on Jan 14th, 2010

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;
 
})();
  • Twitter
  • Facebook
  • StumbleUpon
  • Google Reader
  • Reddit
  • Share/Bookmark

30 Responses

  1. Gary Says:

    Will definitely be trialling the script as above. Thanks for sharing Mike.

  2. Alex Says:

    This does not work in Safari 5.0.

  3. Jraz Says:

    Just following up to Alex’s post, how come this works on most browsers but not Safari?

  4. GogeoffeloJeK Says:

    faxless payday loansfaxless payday loans , http://quickfaxlesspaydayloanonline.com/#15222 payday loan online

  5. lemsfoems Says:

    generique viagraviagra en ligne , http://acheterviagraenlignefr.com/#15830 acheter viagra en ligne

  6. Roahalgop Says:

    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

  7. Pharmf224 Says:

    Hello! dkdbaea interesting dkdbaea site! I’m really like it! Very, very dkdbaea good!

  8. Buy online ativan Says:

    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.

  9. Kirtanuls Says:

    +- levitra no prescription
    levitra online no prescription
    http://buylevitraonlinetoday.com/#79800 — generic levitra no prescription

  10. What is the adverse reaction of ativan Says:

    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.

  11. Stendra Says:

    topcunjlf.hsjggjui, Cialis levitra staxyn stendra and viagra, DIlNyMF, [url=http://stendra365.com/]Stendra[/url], JcWWScs, http://stendra365.com/ Stendra, EKGKuZo.

  12. Sandy Says:

    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.

  13. free coupon code Says:

    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!

  14. dgk Says:

    Pretty component to content. I just stumbled upon
    your website and in accession capital to say that I get
    actually loved account your blog posts. Anyway I will be subscribing for your
    feeds or even I success you access persistently rapidly.

  15. www.experienceproject.com Says:

    We’re a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable information to work on. You have done an impressive job and our whole community will be thankful to you.

    Have a look at my page: Klonopin (http://www.experienceproject.com)

  16. website Says:

    Foor thhe reason that the admin of this site is working, no hesitation very rapidly it will be
    renowned, due to its quality contents.

  17. GritietGrophy Says:

    michael kors handbags outletI agree. If you’re going into an all in one discussion,have to worry about for that reason along with going to be the sake such as going to be the discussion. I’ve heard that posting words of flattery will allow for one’s search engine rankings,regardless that I have serious doubts about that when compared to going to be the heart including SEO,articles or blog posts titles, and quality links. Lord knows, I could be wrong..michael kors outlet
    michael kors purses outletSee this let me feel that material and preferences often ach and every important Meet all of our should is because king. Our market tends to be that an all in one large market in some women.Care a good deal more about all of our need.michael kors factory outlet
    michael kors outletsCool! I dont suppose Ive learn something a little as though this before. So good in order to find somebody leaving a few of these numerous things ideas everywhere in the this subject. realy thank all your family members as well as for beginning this floating around this website could be the something that is that often needed all around the going to be the to acheive somebody to have somewhat originality.integral is the domain if you want too bringing something many of the new to explore the aimed at your website!michael kors factory outlet

  18. unrequepymn Says:

    ugg saleThis article tells my hand I can be able to get a lot of a great deal more goods, quality 100% reliable, I if you find that invest some time to educate yourself regarding break into going to be the mall to learn more about go out and purchase going to be the network significantly more useful things.Save you much in the way just how long before it’s too late.uggs clearanceKeep going to be the space between heart and brain; At times,going to be the ability can’t catch in the air providing some one the mind.ugg boots for saleLife may be meaningless about whether or not everything usually as a consequence easily achieved.What does don’t destroy my hand makes my hand stronger.ugg outlet onlineThank your family thus much in the way as well as for your information. Thanks this is always that ach picking too meuggs sale

  19. abocaittils Says:

    ugg australiaAs I have just begun painting, I would be that the benefit from to learn more about learn more about this many of the new craft and share a resource box to have my own personal friends.discount uggsI have been doing crafts in your an form or at least numerous since I was five. I be able to get excited when anyone shows interest throughout the taking in the air a multi functional craft. So using the success for more information about everyone ugg bootsthis post to video I also watched aspect before; He was great singer on foreigners’ eyes, they were crazy as well as for him,but take heart the player didnot be the case popular on the his mother land; Don’t throw in the towel easily as well as the dream,a resource box can be shinning someday; ugg outlet storeIf all your family members want to learn more about become going to be the fashion a newborn,in a timely manner came to understand more about this site,all your family members can learn a lot of the essence much like the place where all your family can save a lot more money for more information regarding grab those a luxury I was still hesitant about a resource box I have succeeded uggs outletTo be the case honest I think the an important thing to really getting it is certainly plausible to comment will be the delivering for you quality content pieces that in no way possibilities is the fact that do nothing more than informative,but a fun time to learn more about read. Too many bloggers you come up with a little as though a multi functional dictionary no offense to learn more about anybody); I mean about whether or not I’m reading something and then for going to be the sake for example reading aspect I want value, information, entertainment and a multi function story! ugg boots on sale

  20. Tophorparrirm Says:

    michael kors outletsThen I leave.michael kors outlet
    michael kors pursesHaving been learning, teaching and using English as have the desired effect language as well as for in excess of 10 some time I am quite confident that I am a multi functional in line with the English user. I am quite interested for the reason that task. Please i am going to are aware of that about whether or not all your family think I am qualified, please send me a message. I\’d slightly like for more information on learn significantly more about the task and your website.michael kors outlet
    michael korsWay great and ach informative just Sam,web site commenting is because an all in one ach in line with the SEO strategy .But i usually a little as though the forum submission many patients.Because It in no way only is helpful for link building but also will allow all your family members to understand more about be capable of geting good backlinks all of which often ach much in the way invaluable to explore can get going to be the in line with the page rank for a multi function particular website.michael kors outlet

  21. Viagra or cialis Says:

    fgafbnjlf.hsjggjui, Buy cialis online without a prescription, xgmZjKt, [url=http://itwitterfollowers.com/]Buy cialis phentermine[/url], mwRVKsv, http://itwitterfollowers.com/ Levitra vs cialis, kXMqQKa.

  22. Invoidocobvox Says:

    mens ugg bootsThanks a multi functional piece of land SAM,as well as for the i like your article about best five ways to explore need to bother about your online business commenting. This usually an extra ordinary and easy for more information about realizing article that i usually was do you need many years But i for a minimum of one significantly more thing all your family members ricky to be added about going to be the way in order to discover similar to should adhere to your corporation Thanks too sharing my hand in the following paragraphs.ugg boots for womenToday I saw an article that a number of us wrote each girl’s voice,to understand more about become familiar many similar to all of our needs. I think the affected person is usually that best one in your your life,maybe I can be the case a multi function good princess as part of your street.cheap uggs outletHope this condition can be solved in your hospital. So easy and quick to make an appointment with,going to be the doctor is not at all possible to understand more about learn each patient’s condition. Hope a number of us can can get significantly more benefiting.ugg boots for kidsThen I leave.uggs for cheap

  23. Breeriwal Says:

    Abilify Drug Pharmacy Alternative Arthritis Foundation The Drug Tramadol Interactions Buy Cafergot No Prescription Pharmacy. Zyprexa Vs Abilify Don Wind Hair Loss Oxycodone And Tylenol With Codeine Pulmicort Respules No Prescription . B Diflucan B Without Rx Lexapro Geriatric Escitalopram . Testosterone Pharmacia & Upjohn Zoloft And Topamax Medications Imitrex Online Discount Prevalence For Hypertension Acai Berry Power 500 Chemical Ambien Urinary Retention National Diet Weight Loss

    Azithromycin Buy Now – Buy Azithromycin In Australia
    Albenza Without Prescription Mexico – Albenza Use In Canada
    Buy Cheap Cefadroxil With Mastercard – Buy Cefadroxil Overnight Shipping
    Buy Diclofenac Canadian Pharmacy – Get Diclofenac Overnight
    Buy Lioresal Online With Mastercard – Generic Lioresal Ingredients
    Buy Cod Day Next Zanaflex – Zanaflex Next Day Nausea
    Generic Aberela Online No Prescription – Cheap Aberela Cod Free Fedex

  24. svensk slots Says:

    First of all I want to say superb blog! I had a quick question that I’d like
    to ask if you do not mind. I was interested to find out how
    you center yourself and clear your thoughts prior to writing.
    I’ve had trouble clearing my mind in getting my thoughts out
    there. I do take pleasure in writing but it just seems like the first 10 to
    15 minutes tend to be lost simply just trying to figure out how to begin.
    Any suggestions or hints? Appreciate it!

  25. Buy Furosemide Lasix online Says:

    Thanks for a marvelous posting! I actually enjoyed reading it, you could
    be a great author. I will be sure to bookmark your
    blog and may come back later in life. I want to encourage continue your great writing, have a nice afternoon!

  26. john Says:

    TK8gO2 http://www.MHyzKpN7h4ERauvS72jUbdI0HeKxuZom.com

  27. instant quick loans Says:

    Excellent beat ! I would like to apprentice even
    as you amend your site, how can i subscribe for a blog site?
    The account helped me a applicable deal. I had been a little bit acquainted of this your broadcast provided brilliant transparent concept

    My website instant quick loans

  28. ehdhdoro Says:

    His Ruggedness This type what is garcinia cambogia extract? [url=http://garciniacambogiastores.net/garcinia/garcinia-cambogia-fruit/garcinia-cambogia-extract-best/amount-benefits-interconnected/463-everyone.php]if I buy garcinia cambogia can i get a refund[/url] garcinia cambogia weight loss http://garciniacambogiastores.net/garcinia/garcinia-cambogia-fruit-extract/garcinia-cambogia-weight-loss-exceptional/election-checks-re-counted/2406-everyone.php the other hand, suggests.

  29. aquaponics systems Says:

    An Aquaponics garden can be set up indoors or outdoors within the backyard.
    You can use the river for your garden to reduce the waste, but
    360 liters is to much for a traditional sized garden.
    Bacteria like nitrobacter can handle breaking down the ammonia that is being continually created by the fish.

  30. link backlink Says:

    I am regular reader, how are you everybody? This article posted at this web page is in fact nice.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.