« September 2007 | Main | November 2007 »

October 2007 Archives

October 31, 2007

Safari browser now available for Windows

For those of us who don't have immediate access to a Mac for testing our code, there's now a tool to help. Apple has released a version of its Safari (Beta 3) browser for Windows. It uses the same rendering engine, WebKit, on both Mac and Windows (as well as on the iPhone, for that matter), so you can be reasonably confident that web sites tested in Safari on Windows will render and behave similarly on the Mac. (I am not advocating that anyone completely skip testing on non-Windows platforms, just saying that there's a quick "cheat" available.)

JavaScript for centering a popup window to the screen

Ever wondered how to get your popup windows to center themselves on screen instead of appearing wherever your browser wants to put them? Just measure window.screen.width and window.screen.height. Divide each of them in half to get the center point of your screen. Then subtract from those numbers half of the width and height of your popup window. The result is the X,Y coordinates of where you should place the upper left corner of your popup to make it centered:
function newWindow(windowName, URL, width, height, scrolling) {
	width = width || 400;
	height = height || 360;
	scrolling = scrolling || 0;
	
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	
	window.open(URL, windowName, 'width=' + width + ',height=' + height +
 ',location=no,resizable=yes,scrollbars=' + scrolling + 
',screenX=' + topX + ',screenY=' + topY);
}

October 22, 2007

Validating multiple emails in one field-- server-side

My previous post addressed how to use a client-side script to validate a To:, Cc:, or Bcc: field that may have more than one email address. Since not all people have JavaScript enabled, it's always a good idea to validate on the server as well-- and with multiple emails, you can't just use the function IsValid('email', [field value]) to validate. So, I converted my JavaScript function to ColdFusion code.

Continue reading "Validating multiple emails in one field-- server-side" »

October 18, 2007

Validating multiple emails in one field

I'm updating Webmail, a web-based email client that is one of my older projects. I wanted to add client-side validation to the To:, Cc:, and Bcc: fields in the composition form, but I quickly realized that a simple regular expression match for one valid email address wouldn't ensure that the whole field was valid because there would likely be multiple emails in each of those fields. Plus, each email may or may not have a name in front of it. So here's how I coded the JavaScript function to validated multiple name-formatted emails in real time.

Continue reading "Validating multiple emails in one field" »

October 4, 2007

Simple browser and OS sniffing in ColdFusion

It still happens these days that every so often you have to write different code for different browsers-- you might output different form controls for Firefox versus IE, or might write in different stylesheets for older browsers, or you might write out different JavaScripts for IE5 on the Mac. So what's the easiest way to tell which browser and OS is calling your page?

Obviously, you can look through the server's CGI variables too see this information. But you don't want to parse through it every time you have an if-else condition, so I suggest identifying this information once per request or even just once per session with the following code:

<!--- Get the user's platform and browser --->
<cfif CGI.HTTP_USER_AGENT contains "MSIE">
	<cfset REQUEST.userAgent = "IE">
<cfelseif CGI.HTTP_USER_AGENT contains "Opera">
	<cfset REQUEST.userAgent = "OP">
<cfelseif CGI.HTTP_USER_AGENT contains "Safari">
	<cfset REQUEST.userAgent = "SF">
<cfelseif CGI.HTTP_USER_AGENT contains "Netscape">
	<cfset REQUEST.userAgent = "NS">
<cfelseif CGI.HTTP_USER_AGENT contains "Gecko">
	<cfset REQUEST.userAgent = "MZ">
<cfelse>
	<cfset REQUEST.userAgent = "NS">
</cfif>

<cfif CGI.HTTP_USER_AGENT contains "Mac">
	<cfset REQUEST.platform = "Mac">
<cfelseif CGI.HTTP_USER_AGENT contains "Linux">
	<cfset REQUEST.platform = "Linux">
<cfelse>
	<cfset REQUEST.platform = "PC">
</cfif>

Afterwards, you can just refer to REQUEST.userAgent and REQUEST.platform to get the user's environment.

October 2, 2007

Updates and fixes for Microformats CFC

I've posted an update to my microformats CFC today. There are two bugfixes and several XSLT updates (thanks to Gideon Marken for bringing my attention to most of these issues.):

Bug fixes:

  1. microformat classes would not be found in a string if they were combined with other class declarations (i.e., the CFC would find <div class="hcard"> but not <div class="pagetitle hcard">). The regular expression to match classes was updated to fix this issue.
  2. the CFC would fail to recognize microformat strings as valid XML if they contained an unescaped ampersand ('&', often found in URLs, should be '&'). The CFC now automatically escapes all ampersands when parsing microformats out of a string.


Updates:
  1. xhtml2vcard.xsl was updated to the latest version as found on http://hg.microformats.org/x2v.
  2. xhtml2vcal.xsl was updated to the latest version as found on http://hg.microformats.org/x2v.
  3. mf-templates.xsl was updated to the latest version as found on http://hg.microformats.org/x2v.
  4. hAtom2Atom.xsl was updated to the latest version as found on http://hg.microformats.org/x2v.

You can download the CFC from my microformats CFC project page.