sixohthree.com

::

JavaScript Bookmarklets

I wrote my first bookmarklet as a proof-of-concept the other day. I often find myself shortcutting up to the location bar to switch between development and production web servers. Here’s a bookmarklet that toggles “dev” and “www” subdomains for me, broken into a few lines for readability:

javascript:dL=document.location;
nH=dL.host.split('.')[0]=='www'?'dev':'www';
dL.href=dL.href.replace(/^(https?:\/\/)[^\.]+/i,"$1"+nH);

And in its ready-to-drag-to-your-bookmark-bar version: switch.

Respond

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>