Showing posts with label website. Show all posts
Showing posts with label website. Show all posts

Monday, November 17, 2014

Postback not happening on ASP:LinkButton with Adblock Plus

I recently had a problem while working on an ASP.NET website where I had a page doing a postback on an ASP LinkButton, except in FireFox with AdBlock enabled, the postback just wasn't happening. Clicking on the button resulted in nothing. When I examined the markup on the page it looked like this:

<a id="ctl00_ctl00_MainContent_Content_btnReserveTickets" class="btn" href="javascript:__doPostBack('/* postback param*/','')">Buy</a>

It looked like the Javascript initiating the postback should have been firing. I put a breakpoint i that __doPostBack function, but it didn't get hit. There were no console errors either. I racked my mind and googled around with no luck. The only potential solution I could find - to add a CausesValidation="false" attribute to the LinkButton - didn't work.

Finally I posed my question on StackOverflow and walther over there gave me a hint that led to the solution. He suggested that I look for AdBlock's blacklisted keywords that may have been attached to the name or attribute or something of the LinkButton, such as "ad" or "facebook" or so on and so forth.

In the end, I discovered that there was a function adding a click handler to the LinkButton that was sending a Google Analytics event, as follows:

$(anchorEl).click(function () { 
                        ga('send', 'event', 'outbound', 'click', anchorEl.href, {
                            'hitCallback':
                              function () {
                                  document.location = anchorEl.href;
                              }
                        });
                        return false;
                    }); 

It turns out that once this click event gets attached, and because it's Google Analytics, all javascript on the LinkButton gets stripped off!

In the end this blogpost guided me to a solution: I wrapped the click event binding above in the following if statement:

if (ga.hasOwnProperty('loaded') && ga.loaded === true) {
    // bind event
}
This means that if AdBlock is ever blocking Google Analytics from loading, the anchorEl's click event is never bound to that Google Analytics event (binding it successfully would be useless anyway, since Google Analytics isn't loaded), and AdBlock doesn't strip the Javascript from my LinkButton.

Thursday, September 25, 2014

Lessons From Building My First Website

I made my first website at http://searchgovernmentjobs.org/ a few days ago - it's at a thin wrapper around a government API that I found at http;//digitalgov.gov. It allows you to search the government API for jobs using queries, examples of which I've included on the search page. The results are all from http://usajobs.gov.

My original intention was to just get something out there on the internet. In doing so, I learned some valuable lessons:
  • I learned about DigitalOcean (disclaimer: referral link), based on a question I had asked on HackerNews
  • I learned at least the basics of navigating the default Django stack that comes on a DigitalOcean Django droplet. See my post here for one such lesson that I learned. 
  • I learned how to buy a domain name at 1and1.com. (disclaimer: referral link)
    • Fun Fact: I had originally intended to name the site: searchgovernmentjobs.us - but it turns out that using the .us TLD forbids you from using the privacy coverage provided your hostname provider. It has to do with the rules of the organization that administers the .us TLD. 
  • I learned how to configure the 1and1 DNS record to point to the nameservers at DigitalOcean
  • I learned that there are Adsense alternatives. I'm using Chitika for the moment. (disclaimer: referral link)
Now that I have the site up, I'm going to look and see if I can do some SEO to get it up the ranks in search engine pages. Ideally, I would like the site to be self-sustaining in that it should pay for hosting and domain fees out of its own ad revenue, but I don't anticipate being very successful in this regard. The Jobs spaces is pretty filled up with SEO optimized sites and the keywords are very crowded. Nonetheless, I shall try, and in doing so, I may learn something about SEO.