Firefox: Open in Blank Tab

If you don’t use Firefox 3, go get it. Then finish this article. (Safari and Opera users are excused, but there’s no promise this will work for them.)

One of my (few) gripes with Firefox is that bookmarks on the toolbar have no “open in blank tab” option. They have an “open in sidebar” option, but those uses are rare and esoteric at best. Personally, I never use the sidebar.

“Open in blank tab” should basically do this: if there is a blank tab, use it; if not, create a new tab. Frankly, it could just open in a new tab regardless, but it seems like such an easy thing to add.

But? It can’t be done directly in Firefox. Hence, I present this small script:

1.
javascript:
2.
(function(){var u=‘http://mail.google.com/mail’;
3.
  if(window.location==‘about:blank’){
4.
    window.location=u;
5.
  }else{
6.
    window.open(u,);
7.
  }
8.
)();
That’s it. Try dragging this link to [GMail](javascript:(function(){var%20u='http://mail.google.com/mail';%20if(window.location=='about:blank'){window.location=u;}else{window.open(u,'');}})();) to your bookmark toolbar. Then click the link on your toolbar. Now, open a new tab, and click the link again.

This isn’t exactly what I asked for. It has no way of knowing if any blank tab exists, only if the current tab is blank. And, of course, it lacks the nice favicon support.

But it does the job. If you change the variable u to something other than ‘http://mail.google.com/mail’, you can make the link open any other page.

I love anonymous functions.

Update: If you want a bookmark for something besides GMail, you can [create your own](javascript:(function(){var u=prompt('Enter the URL to open in a blank tab.','http://');prompt('Copy the text below into a new bookmark.',"javascript:(function(){var u='"+u+"';if(window.location=='about:blank'){window.location=u;}else{window.open(u,'');}})();");})();). Or you can drag this link to your toolbar, to make new ones whenever you want: [Open in Blank Tab](javascript:(function(){var u=prompt('Enter the URL to open in a blank tab.',window.location);prompt('Copy the text below into a new bookmark.',"javascript:(function(){var u='"+u+"';if(window.location=='about:blank'){window.location=u;}else{window.open(u,'');}})();");})();).

Update 2: Oops, fixed the “create your own” link. Tested it, then accidentally pasted in the results, instead of the actual script.