views:

41

answers:

2

Is there a JavaScript hack I could place in the URL field which would guide mobile browsers to "m." prefixes and guide my desktop to "www." prefixes, if I provide the "<domain>.<root>" suffix?

I think this would be useful for both Weave and Opera Link users.

+2  A: 

Your problem is that window.location.href is a property, not a method.

You're trying to set the browser location by code along the lines of:

window.location.href("http://www." + address)

What you should be using instead is

window.location.href = "http://www." + address;

If you change your bookmarklet accordingly, it seems to function correctly (i.e. it takes me to www.cnn.com when I paste it into my address bar). I thought about posting the corrected code here but on reflection I think that would be patronising.

Andrzej Doyle
A: 

A Working Script:

javascript:(function(){url="digg.com";if(screen.width<=480&&screen.height<=320){window.location.href="http://m."+url}else{window.location.href="http://www."+url}})()

_ande_turner_