Tag Archives: javascript

javascript get locale month with full name

JavaScript Date object

The Date object in JS helps you work with dates as it sounds logical. However there are limited number of functions attached to it which you can use. You can check for full Date specification in w3schools : here.

How to get the month name?

Normally when you try to use a date object you can format it with the following code:

var d = new Date();
alert(d.getFullYear());
alert(d.getMonth());
alert(d.getDate());

The problem is that you cannot reference the date object and to get the full name of the month. Something like d.getFullMonth()!

That’s why the easiest way to get the full month name is to make a custom locale array such this one:

var monthLocale = new Array(12);
monthLocale[0] = "January";
monthLocale[1] = "February";
monthLocale[2] = "March";
monthLocale[3] = "April";
monthLocale[4] = "May";
monthLocale[5] = "June";
monthLocale[6] = "July";
monthLocale[7] = "August";
monthLocale[8] = "September";
monthLocale[9] = "October";
monthLocale[10] = "November";
monthLocale[11] = "December";

And than you can simply reference the locale array!

javascript: what is typeof typeof

typeof

If you’ve ever heard about typeof operator in javascript than, how about those few questions:

  1. what is typeof typeof ‘string’ ?
  2. what is typeof typeof?

Answers

The first one is “string”. Yes if there you have the following code:

typeof something_undefined

that gives of course undefined, but if there is typeof typeof something_undefined the answer is string, because “udefined” itself is a string.

The second question is simple javascript error, there is no case with typeof typeof only.

javascript: detect browser speed and load the “slow connection” site version

How to detect the browser speed?

It’s easy, you just put a ajax or image load in the beginning of the page and than you know what the speed is. But the problem is that the ajax and the image load need to finish to know exactly how slow or fast the connections is. And even worse, you need to slow down the page even for normal (fast) connections. And where’s the point? You get the site slower only to understand the connection. That’s not OK.

The javascript blocks the page load

That’s another problem with javascript. You know when you have script tag in the head of the document, the browser needs to finish loading this javascript, parse it and than continue loading.

How javascript can be loaded async

Well there are several methods, but here we need only one separate javascript that don’t communicate with other JS code in the site, it only get information about the connection speed.

Put the javascript code in an Iframe.

Than the loading of that javascript is async. Independently you continue loading the site. For fast connection, yes this going to slow down a little bit, but however not as much as if you put an inline code. Than in that iframe you can simply check for an expression to verify for a slow connection if it’s true you may set a cookie for slow connection site version and reload the window.parent of the iframe, which is the page itself.

jQuery datepicker persist defaultDate

Datepicker from jQuery

You know how the jQuery UI extensions give a useful functionality for the javascript developers. The datepicker is a useful calendar tool that comes with variaty of functions.

How to setup the selected / defaultDate

It’s as simple as these lines of code:

$('#element_id').datepicker({
    ...
    defaultDate : d,
    ...
});

The problem

The problem is when you attach this datepicker constructor to a div which is hidden, and than you make it visible like so: Continue reading jQuery datepicker persist defaultDate →