Sunday, November 13, 2011

Multi-page Javascript Bookmarklet

[Disclaimer: I don't know crap about javascript, other than what I pieced together from the 'tubes.]
I read something somewhere (I don't remember where) about having a bookmarklet that automatically opens your favorite sites, each in their own tab, when you click on it. I wanted to set up my own, but the article didn't explain how to do it (just suggested it as an idea). It's actually pretty easy.  Below is commented code:

javascript:(function(){
  /* save a reference to the current window */
  oldWin=window;
  
  /*
   * Replace the current window's or tab's website with this one.
   * If you just want additional windows (or tabs) opened
   * skip this.
   */
  location.href='https://mail.google.com';
  
  /* Each additional window/tab you want opened */
  window.open('https://voice.google.com');
  window.open('http://www.accuweather.com');
   
  /* restore focus to the original tab, since each
   * new window gets focus
   */
  oldWin.focus();
})();

Paste this entire javascript fragment in as the address for your bookmark. It may be easier to bookmark an arbitrary page, then edit that bookmark's title and address.