javascript - Detect when tracking pixel is returned from server -


customers use service install script (javascript) server. have tracking pixel inserted onto page via script picks click info.

when asp.net server intercepts pixel.aspx inserts login information fake image's querystring database , returns pixel.gif...all works (see below).

imports microsoft.visualbasic imports system.web  public class helloworldmodule implements ihttpmodule private pattern string = "/images/(?<key>.*)\.aspx" private logofile string = "~/images/pixel.gif"  public sub new() end sub  public readonly property modulename() string             return "helloworldmodule"     end end property  ' in init function, register httpapplication  ' events adding handlers.  public sub init(byval application httpapplication) implements ihttpmodule.init     addhandler application.beginrequest, addressof getimage_beginrequest end sub  public sub getimage_beginrequest(byval sender object, byval args system.eventargs)     'cast sender httpapplication object     dim application system.web.httpapplication = ctype(sender, system.web.httpapplication)      dim url string = application.request.path 'get url path     'create regex match becon images     dim r new regex(pattern, regexoptions.compiled or regexoptions.ignorecase)     if r.ismatch(url)         dim mc matchcollection = r.matches(url)         if not (mc nothing) , mc.count > 0             dim key string = mc(0).groups("key").value             'savetodb(key)         end if          'now send image client         application.response.contenttype = "image/gif"         application.response.writefile(application.request.mappath(logofile))         application.response.end()     end if end sub 'getimage_beginrequest 

if client running script has expired account want return error.gif in response (instead of pixel.gif) , need detect error.gif src can notifiy client service has expired.

i have tried following, returns original src of image. how detect updated src of image?

any or suggestions appreciated.

testimage("images/pixel.aspx?login=123&country=canada", function (url, result) { if (result === 'success') { console.log(url) } }, 10000);       function testimage(url, callback, timeout) {         timeout = timeout || 5000;         var timedout = false, timer;         var img = new image();         img.onerror = img.onabort = function () {             if (!timedout) {                 cleartimeout(timer);                 callback(url, "error");             }         };         img.onload = function () {             if (!timedout) {                 cleartimeout(timer);                 callback(url, "success");                 console.log(checkurl(url))             }         };         img.src = url;         document.body.appendchild(img);          timer = settimeout(function () {             timedout = true;             callback(url, "timeout");         }, timeout);     }   function checkurl(url) {         return (url.match(/\.(jpeg|jpg|gif|png)$/) != null);     } 

i never found identify image src, due server sending pixel.gif before page rendered no script ever detect src change. put logic on server when customer account expired, display message on requesting web page of account expiry...

' in init function, register httpapplication  ' events adding handlers.  public sub init(byval application httpapplication) implements ihttpmodule.init     if acct_expired = false         addhandler application.beginrequest, addressof getimage_beginrequest     else         addhandler application.beginrequest, addressof application_beginrequest ' getimage_beginrequest     end if  end sub  public sub getimage_beginrequest(byval sender object, byval args system.eventargs)     'cast sender httpapplication object     dim application system.web.httpapplication = ctype(sender, system.web.httpapplication)      dim url string = application.request.path 'get url path     'create regex match becon images     dim r new regex(pattern, regexoptions.compiled or regexoptions.ignorecase)     if r.ismatch(url)         dim mc matchcollection = r.matches(url)         if not (mc nothing) , mc.count > 0             dim key string = mc(0).groups("key").value             'savetodb(key)         end if          'now send image client         application.response.contenttype = "image/gif"         application.response.writefile(application.request.mappath(logofile))         application.response.end()      end if end sub 'getimage_beginrequest  private sub application_beginrequest(byval source object, _          byval e eventargs)     ' create httpapplication , httpcontext objects access      ' request , response properties.      dim application httpapplication = directcast(source, httpapplication)     dim context httpcontext = application.context     dim filepath string = context.request.filepath     dim fileextension string = virtualpathutility.getextension(filepath)     context.response.write("<hr><h1><font color=red>your account has expired. upgrade today!</font></h1>") end sub 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -