Skip to content

A bookmarklet

October 19, 2011

This is a little silly, but…

Remember bookmarklets? They can still come in handy. In most places I’ve worked, there is at least 3 servers: one for development, one for qa, and one for production. If you use a content delivery network, add an origin server, and if you use a local environment, you can add that, too. That’s at least five servers that potentially have the same file on it, in various states of development.

This is just a quick little javascript function that:

  • has an array of all these servers (just the protocol and hostname, minus the trailing slash)
  • finds everything past the first slash after the hostname
  • checks to see if the hostname you are currently on is in the array
  • and then loads all servers in the array as new tabs or windows, minus the one you have open

Here’s the full function:

function loadUp(){
	var sites = [
		"http://www.cbc.ca",
		"http://www.google.ca",
		"http://www.yahoo.ca",
		"http://www.wikipedia.org"
	], i, value, site, proto, ref, url=window.location;
	site = url.host.toString();
	proto = url.protocol.toString();
	value = url.pathname.toString();
	ref = proto + "//" + site;
	for(i = 0; i < sites.length; i++){
		if(ref != sites[i]){
			window.open(sites[i] + value + url.search + url.hash);
		}
	}
}

And this is the ridiculous one-line bookmarklet (the bookmarklet is slightly modified to work on one line):

javascript:sites=['http://www.cbc.ca','http://www.google.ca','http://www.yahoo.ca','http://www.wikipedia.org'],url=window.location;site=url.host.toString();proto=url.protocol.toString();value=url.pathname.toString();ref=proto+'//'+site;for(i=0;i<sites.length;i++){if(ref!=sites[i]){window.open(sites[i]+value+url.search+url.hash)}};window.location=window.location;

This opens tabs in Firefox and Chrome, and new windows in Safari and IE.

All you do is modify the array I have, pop it into a link, bookmark it, and you have the ability to see any page on your web site in all environments.

Enjoy!

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: