The first is to create a vhost in your webserver that serves an index.htm page on your NON-www url. The contents of that page would simply redirect users to the www.yourdomain url.
If that seems like too much work, an even easier fix (truncated for brevity) is to do something like this:
var url = window.location.href;
if(url.indexOf("http://www") != 0) {
window.location.replace("http://www.yourdomain/");
}
You'd obviously want to capture the remainder of the querystring and add it in, but that's the general idea.