In these days of browser standards, it’s easy to forget that once upon a time, simple tasks like an HTTP request from JavaScript were difficult or even impossible, and if you wanted it to work in every browser, you were going to have to write wrappers to try and create a consistent API.

Zeke inherited an application back from those bad old days. It needs to poll a server, and based on the response, it performs an action, but it does this in an “inventive” way.

First, they fashion a rudimentary enum:

    var Response = {
            nothing: 1,
            showInviteNewWin: 2,
            showInviteSameWin: 3,
            pushPageSamewin: 4,
            pushPageNewWin: 5,
            inviteTimeOut: 6,
            resendInfo: 7,
            neverInvite: 8,
            stop: 9,
            notCurrentPage: 10

They’re going to use that in a moment to parse the server’s response, but first- how are they going to send a request?

    var na_pro_img = null;
    function sendVisitInfo() {
        na_pro_img = null;
        na_pro_img = new Image();
        na_pro_img.onload = checkResponse; /*imageLoaded;*/
        var d = new Date();
        na_pro_img.src = prefix + 'Visitor.aspx?Cmd=1&TITLE=' + escape((document.title != "") ? document.title : document.location) + '&REFERRER=' + escape(document.referrer) + '&LASTVISIT=' + escape(lastVisitCookie) + '&LASTINVITE=' + escape(lastInviteCookie) + '&RSND=' + resendCount + '&CUSTOMVARIABLES=' + escape(custProp) + '&LT=' + d.getTime() + ((neverCookie != null) ? ('&NEVERINVITE=' + escape(neverCookie)) : "") + '&cpId=' + curPageID;
        d = null;

Well, that will generate a request, I suppose, with the SRC property passing a bunch of stuff in the URL parameters. But how on Earth are they parsing anything useful out of the response? And what does this have to do with their rudimentary enum?

    function checkResponse() {
        switch (na_pro_img.width) {
            case Response.nothing:
            case Response.showInviteNewWin:
                sessWin = 'n';
             // more cases cut for brevity

They use the width. The width of the image is matched against their “enum”. Through modern eyes, this is the sort of thing that makes you want to go WTF, but for those of us that had the misfortune to do web development back in the days when JavaScript was a novelty and autoplaying MIDI files was the coolest thing you could have on your page…

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!