Christian Heilmann

You are currently browsing the archives for the Odds & Ends category.

Archive for the ‘Odds & Ends’ Category

Massive Bug in Google Maps!

Thursday, September 28th, 2006

[link:,Stuart Colville,colleague friend] just sent me proof for a massive bug in Google Maps! Check it out for yourself!

In case it is fixed, [link:,here’s my flickr copy].

Shortening strings to a fixed length in JavaScript

Friday, August 25th, 2006

I have this function I’ve used for quite a long time to shorten a string to a fixed amount of characters without breaking in between words:

function constrain(str,n){
var words = str.split(’ ‘);
var resultstr = ‘’;
for(var i = 0; i < words.length; i++ ){
if((resultstr + words[i] + ’ ‘).length>=n){
resultstr += ‘…’;

resultstr += words[i] + ’ ‘;

return resultstr;

ately that it can get really slow with massive strings in Internet Explorer. This is a well-known issue and the solution is to use arrays instead of concatenating strings.

This made me realise how convoluted the above example is and that it is much easier to do the same with an array:

function constrain(str,n){
if(str.length > n){
var s = str.substr(0, n);
var words = s.split(’ ‘);
words[words.length-1] = ‘’;
str = words.join(’ ‘) + ‘…’

return str;

You send a string and the amount of characters wanted as parameters and the function returns the string with the right lenght followed by a “...”.

Another way to work around the MSIE issue of slow concatenation is to use thea string builder.

Sneakily reading out your browser history

Monday, August 21st, 2006

Via Stuart Colville I got a URL that uses a sneaky trick to see where you have been surfing. Jeremiah Grossman shows how you can check for visited sites.

The common complaint of developers who don’t see the security and privacy issues with that is that you can read out the history of the window with JavaScript but you only get the amount of visited sites, not their URLs. With this trick, you can.

The trick is pretty easy: He uses a whole array of sites to check against, writes out a style for visited links to the page, writes out a list of these links and checks their computedStyle color attribute against the colour he set in the style. If it is the same, the page is in cache and has been visited beforehand.

I already commented that it may be more stable if you set a different style to the visited links like display block and a height and read the offsetHeight instead of computedStyle. In any case, it is a clever and worrying trick.

Safari for Windows – well almost

Tuesday, August 8th, 2006

You can now get a WebKit based browser for PC, which allegedly works and renders like Safari.

It is called Swift and can be downloaded at

In order to keep the original PC/Windows vibe going, the install will crash unless you apply a patch beforehand.

Testing ahoy!


Workfriendly surfing

Wednesday, August 2nd, 2006

Workfriendly I just stumbled upon workfriendly, a web service that shows a web site inside a frame that looks like it is Microsoft Office Word 2003. The clue is that instead of just showing the page in the frame, the service also turns off imagery and layout and makes the web site appear as if it was a Word document. Perfect for those offices where the boss frowns upon web surfing.