Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Friday, May 20, 2011

Associative JavaScript Arrays by Numeric 'ID'

I needed to keep browser-side information about certain objects by numeric ID.
When using an associative JavaScript array like this:

var gadgets;
gadgets[4711].name = 'Fred';
gadgets[4711].color = 'red';

you will find that it creates an array with (mostly empty) elements gadgets[0] to gadgets[4711].
On the other hand, when initializing the array like this:

gadgets['4711'].name = 'Fred';

it creates a single element in an associative container. Once created, you can access such elements with either gadgets[4711] or gatgets['4711']!

Friday, May 28, 2010

iphone, blackberry, mobile web pages

When trying to create web pages for web browsers in mobile devices, the initial idea might be to simply create "small" pages which for example contain images with a widths of 480 pixel that should fill the display of a 480-pixel-wide phone.

In reality, that image might then only use about 50% of the screen!

Reason: Mobile web browsers pretend to be like a desktop web browser, for example having close to 1000 pixel screen width, and then scale the web page down to fit onto the physical display, so a 480 pixel images uses 480/1000 = about 50% of the screen.

One important hint is this HTML tag that instructs the mobile web browser to use the phyisical screen widths:


<meta name="viewport" content="width=device-width">

See