26 August, 2011

Chrome tip: Open new tab next to current tab, using JavaScript in a search engine "bookmark"

In the Chrome browser, the keystroke for opening a new, blank tab (Ctrl-T or Cmd-T) always opens the tab at the far right of all tabs. Usually I would prefer it to open to the immediate right of my current tab.

You can do this by right-clicking on your current tab and selecting "New Tab" but I prefer keystrokes to mouse actions.

You can also do this with the Tab to the next right extension (a deservedly popular extension), but it also controls which tab will be selected when you close one and I prefer to use Chrome's own selection method. Also, sometimes I DO want the tab to open at the far right. :)

I've worked out that I can get what I want with some JavaScript in Chrome's search engine preferences. I tested it only on a Mac so the steps might be slightly different on other devices. It looks like a long process but it's really very simple.
  1. Go to Chrome's Options / Preferences screen (click the wrench icon on the browser toolbar then select Options or Preferences -- whichever appears on your system).
  2. You'll find yourself in the "Basics" preference page, which should have a "Search" section. Click on the Manage Search Engines... button.
  3. You'll see a list of your custom-built search engines for various sites (if curious, read about Chrome's search engine configuration). At the bottom of the screen, find the set of empty fields for adding a new search engine.
  4. In the first field (labelled "Add a new search engine"), enter Open new tab or something similar. The words you choose are not important -- make them meaningful to you so they'll trigger your memory if you go back into this screen any time in the future.
  5. In the second field (labelled "Keyword"), enter a single word or single letter or a sequence of letters (no spaces nor punctuation). You'll be typing this every time you want to open a new tab to the immediate right, so short and memorable is good. I use tt
  6. In the third field (labelled "URL with %s in place of query"), enter exactly this text including the semi-colon at the end:
    javascript:window.open();
  7. Click anywhere outside the fields to "save" your entry.
That's the end of the set up. Now whenever you want to open a new tab next to your current tab, you can do this:
  1. Move the keyboard focus to the address bar (Ctrl-L or Cmd-L).
  2. The entire current address should be highlighted, but if not, highlight it all (Ctrl-A or Cmd-A).
  3. Type the keyword you chose in step 5 above -- e.g., tt -- and hit Enter or Return.
Once you get used to doing this, you'll be able to do it very quickly: Cmd-L tt Enter

The new tab will open immediately to the right of your current tab. Your current tab will not be affected except that the URL might have disappeared from the address bar; if you want to see the URL again, just reload the page hit the ESC key (thanks lehrblogger for your tip!). If you ever want to open a new tab at the far right of the address bar, use Chrome's default new tab keystroke (Ctrl-T or Cmd-T).

If you know of a better method for opening a new tab next to your current tab, please tell me by comment or email!

9 comments:

  1. I use tons of custom searches, and this one is especially cool, so thanks! If you want to see an URL you've deleted/changed in the address bar, you can just hit the escape key instead of reloading the page.

    ReplyDelete
  2. You can use the same technique to add a button in the Bookmarks Bar.

    1. Open Bookmark Manager.
    2. Select the Bookmarks Bars folder
    3. Select Organize > Add Page.
    4. Name the new page "New Tab" or something similar.
    5. In the URL field, add the javascript mentioned in the above post:

    javascript:window.open();

    You should now have a clickable button to open a new tab.

    ReplyDelete
  3. Thanks, works like a charm! Exactly what I was looking for!

    ReplyDelete
  4. This post is 7+ years old but still contained exactly the info I was looking for. I use a crazy number of keyboard shortcuts and Chrome extensions -- this trick is definitely going to be getting used frequently!

    ReplyDelete
    Replies
    1. Oh hey, that's great to know! Thanks for telling me! :)

      Delete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. this still works, was referenced on SuperUser - thank you

    ReplyDelete
  7. Still works in 2024, huge thanks

    ReplyDelete