Web Dev Notes

Blog about web development by Robert Dawson

Bookmarklet to switch subdomains

If you ever find yourself needing to switch subdomains, such as from beta.mysite.com to www.mysite.com, here is a bookmarklet to make life easier. Because dragging my mouse to the address bar, selecting the entire subdomain, and then tediously typing in a new one is so exhausting!

With this handy bookmarklet, all you have to do is click it and type in the subdomain you want. It's not telepathy, but it's tolerable. To make this bookmarklet, make a new bookmark on any given page and then replace the URL with the following code.

javascript:var env=prompt("Subdomain?","e.g., www");if(env!="e.g., www"){window.location=window.location.href.replace(/http:\/\/(.+?)\.(.+?)\.(.+)/g, "http://"+env+".$2.$3");};