Browser Detection Shim for jQuery

Posted on Wed 06 February 2013 in jQuery • Tagged with jquery browserLeave a comment

We started the process of getting rid of deprecated methods in order to migrate to jQuery 1.9, but the removal of $.browser was a no go for us. I pulled jQuery's browser detection code and packaged it into a closure, with a few minor changes for past encountered bugs, and then simply replaced all instances of "$.browser" in my scripts with "browser". Add this script above the rest of your scrips and make the replace and you'll have your browser detection back. Things like bgiframe() are still necessary for some of us supporting B2B clients on antique browsers, it just isn't possible to use feature detection for some of these cases. I noticed in the comments section on for the release of 1.9.1 some people asking for this, hope this helps.

Ringtones on iPhone without iTunes

Posted on Tue 01 February 2011 in iPhone • Tagged with iphone, ringtoneLeave a comment

For some reason today, boredom or whatever, I was hell bent on getting the Angry Birds theme song onto my iPhone to replace that stupid Marimba ringtone. First task was to find or make the ringtone, I found one offered up for free here Not quite sure yet how I was going to manage getting the ringtone on to my phone, I copied the link for the theme song from the web page,, and emailed it to myself.

Now that I had the link, through trial and error I figured out the rest. There are a couple of apps you'll need to have in order to download the ringtone and get it to the proper place on your iPhone. The first app you'll need is iDownloader, you can find this app in the appstore. The second app you'll need is iFile, which can be found in Cydia, yes your phone will need to be jailbroken to accomplish this, I know I'll see comments about how you could do this all with iFile, or use iFile and the Safari downloader from Cydia. Well i couldn't get the webserver on iFile to start and I happened to have these apps on my iPhone already so this is what I used to make it happen, if you already knew how to do this you could write your own blog post about it...

  1. Start by opening iDownloader and pasting the link into the Address bar, you'll be asked if you want to download the file, let the file download.
  2. Once the download is finished launch iFile, click the gear on the left of the tab bar to open the Preferences page, turn on Hidden Files and Application Names
  3. In iFile, navigate to /var/mobile/Applications/iDownloader/Documents/Downloads/, you should find the File you downloaded, Angry-Birds-Main-Theme-Song.m4r. Click Edit, Select the File, click the far right action icon on the Tab bar and select Copy
  4. Now in iFile navigate to /Library/Ringtones/, click Edit, click the same icon as the previous step and select Paste
  5. Open the settings app, click on Sounds, Ringtone, you should now see the ringtone in the list, select it and enjoy

Sure you can use this technique for any ringtone file you can find on the internet, but I think the Angry Birds theme song makes an excellent ringtone, enjoy.

Writing JavaScript specific CSS

Posted on Wed 22 April 2009 in JavaScript • Tagged with css, javascriptLeave a comment

In your html template or page add a nojs class to your html node and a script tag in the head section below your title changing the className to js:

In this very simple example all of your non-javascript users would see links with a class of myclass as red and all javascript enabled users would see the links with the color black. Both javascript and non-javascript users would see the links with the class myclass2 as blue.

This very simple example opens hundreds of possibilities for the way you style your site. You could actually display and hide content based on whether javascript is enabled or not, including buttons and links or any element on the page. You could include text for Search Engines and Screen Readers that your regular users might not need to see because the nature of the content could be for SEO or descriptive purposes for non-javascript users. You could also use it to enhance your suckerfish CSS menus with a hoverIntent when javascript is enabled making your menus a little more user friendly.

This is an improvement on the previous method I used because it doesn’t depend on a JavaScript framework, it allows you to put off loading all of your JavaScript until the bottom of the page, improving performance, and allows you to utilize CSS to hide, disable, or fade in elements of the page that you don’t want to be displayed until the document has been loaded and is ready to perform all that RIA functionality you’ve added to your app.

Setting your tabindex on your html forms automatically with jQuery

Posted on Thu 18 December 2008 in jQuery • Tagged with input, jquery, tabindexLeave a comment

The tabindex is absolutely necessary for controlling the tab order through a really long form, from a usability and accessibility standpoint. This is probably not the preferred way to do this, you should be setting the tabindex attribute on all of your input elements in your html. Now if you work with lazy developers, that often forget to set the tabindex, you may find this to be an acceptable solution.

Quick walk through:

  1. The outside function is your document ready function in jQuery (explaining for those new to jQuery)
  2. The tabindex variable is there to keep track of the index across multiple forms on the page (another reason you may want to use something like this, if your view code is modular and split into a bunch of snippets or includes)
  3. The select grabs all the input and select elements on the page we then exclude the hidden input boxes
  4. We then set the tabindex and increment the variable

Prevent double submit with jQuery

Posted on Tue 16 September 2008 in jQuery • Tagged with javascript, jquery, submitLeave a comment

Another great "little" solution with jQuery. Needed a simple way to protect all the forms on our site from being double submitted. There was an attempted solution in place on our app, that added an onsubmit to every form with a function above it called ignoreDoubleSubmit that tried to trap the event of the button was clicked and not allow it to be clicked again. The problem was the event for the button wasn't present when the form was submitted so it would silently error out with a blink in the Firebug console. After weeks of fighting to have it fixed, I removed the code and reimplemented a working solution with jQuery

Stock quote and chart from Yahoo in Java

Posted on Sun 17 August 2008 in Java • Tagged with java, stocksLeave a comment

I was recently in need of a stock quote web service in order to display quote information and charts for a corporate website I was working on, so I started looking around for something, free of course. I kept reading that the most common example of web as a service is the stock quote example, but I didn't really find any examples that gave me a warm and fuzzy, everyone seemed to be scraping the html from a page. Doesn't seem to be much out there, in the way of quote services for free, but I did come across a yahoo download service and a few half written examples, where you can fetch quote information from Yahoo in .csv format, with a 20 minute delay of course. I've also added a 1-day small chart and a 5-day large chart image by passing the symbol into Yahoo's basic chart image url.

Input focus with jQuery

Posted on Mon 16 June 2008 in jQuery • Tagged with focus, html, jqueryLeave a comment

Form input focus always seems a pain to me, I don't like all of the generated inline javascript that struts or other frameworks add to accomplish this and it always seems to be one issue or another. So here's a simple solution that applies focus to the last input element in the document that has a class of focus. Short and sweet, nothing fancy, requires the jQuery library of course.

The javascript, preferrably in an external javascript file

Default html button submit on enter with JQuery

Posted on Thu 24 April 2008 in jQuery • Tagged with html, jquery, submitLeave a comment

I basically needed the update button to be the default action on clicking enter in the form, but there were multiple submit buttons in my form and they weren't in the order I needed due to UI design. This was a quick and dirty solution to select an html submit button and make it the default when a user clicks enter from certain or all input elements on the form. It could be tweaked to give specific behavior to specific types of input boxes, such as invoking a tab on enter in between required elements, but the general idea is using jQuery to click the default button when the user hits enter.

Simple Cross Site Scripting (XSS) Servlet Filter

Posted on Sat 23 February 2008 in Java • Tagged with java, xssLeave a comment

Ran into some issues on some of our Java sites today and needed a quick fix to protect the sites from malicious Cross Site Scripting (XSS) attempts. If you're not aware of what XSS is and have websites that have sensitive user data, you may want to read up, you're probably vulnerable, which means your users are vulnerable. I'm not claiming this is a perfect solution, but it was easy to implement and corrected the vulnerabilities with form and url injection. We basically have a Servlet Filter that's going to intercept every request sent to the web application and then we use an HttpServletRequestWrapper to wrap and override the getParameter methods and clean any potential script injection.

I'm sure the cleanXSS replacements aren't the most efficient way of doing this, you could replace it StringEscapeUtils.escapeHtml from commons lang to simplify it a little, it's up to you, it all depends on what your site is doing and whether it's going to be a pain having all the html escaped, you could also adjust the url-pattern of the filter to be more specific to your application urls, so that everything under your app isn't running through the filter.

Some things to be aware of with this approach, you'll need to account for what you've encoded or in some cases you'll end up with weird characters in your database and possibly in validation of your input boxes. Some would recommend a more positive validation rather than negative validation and only allow a certain range of characters, it's up to you, but it is something to think about.

Some notes on this approach, it's old, you should checkout the OWASP website for the latest projects to prevent XSS and other exploits.

Suckerfish DHTML dropdown menu with JQuery

Posted on Thu 21 February 2008 in jQuery • Tagged with javascript, jquery, suckerfishLeave a comment

DHTML dropdown menu's have been greatly improved in terms of accessibility, standards compliance, and weight using the Suckerfish technique of building pure CSS-based menus and then attaching a small javascript that allows Internet Explorer 6 to mimic the CSS hover method. Once the die-hards hanging onto IE6 let go, we won't have to worry much about this anymore, but for now it looks like it's going to linger for a bit.

I've been using JQuery for a bit now for all of my DOM manipulation and have found great savings in the amount of JavaScript code I have to write and the ease in which it can be employed in a CSS based site.

While this is generally the last piece to get IE working with your menu's, here's the JQuery code to replace the suckerfish Javascript, which is being used on this site now. If you're familiar with suckerfish, the JQuery code should be readable enough to figure out what's going on.

I'm putting this post out there for Javier, who reads my blog, but doesn't understand a word of it, and the answer to that burning question is, no my wife won't let me date that girl from work ;)