[an error occurred while processing this directive].com

Go to Home

The best ideas come from finding something you do all the time, realize you do it, and then automate it.

With me, I discovered that I frequently go to the base domain of a website by going to the URL, highlighting and deleting the junk on the end of the domain name and then pressing enter. I HATE doing it. I also have to do it when websites don’t link to their home page.

So here’s an easy solution. A bookmarklet!

Drag the link below to your bookmarks bar (or in IE, right-click and add to favorites):

Here is the code:

var url = new String(location.href);var re = new RegExp(’https?://([A-Za-z0-9.-]+)’);var res = url.match(re);location.href=res[0];

Enjoy :)

20 Comments, Comment or Ping

  1. Goatrider

    I didn’t realize I needed this until I saw it. Thank you, clever man.

  2. Tolli

    I do that a lot two, luckily I found a Firefox add-on that allows me to navigate up a level. It’s called uppity: https://addons.mozilla.org/en-US/firefox/addon/869

  3. Jeff

    Thanks! This is one of those things you wonder how you did without.

  4. Um… brilliant. Fucking brilliant.

  5. Xasey

    Also, if one is using Safari they can right click on the page title at the top of the window to go to there as well.

  6. Lonestar

    Here’s the ubiquity command for the same functionality:

    CmdUtils.CreateCommand({
    name: “root”,
    _root: function() {
    var doc = Application.activeWindow.activeTab.document;
    var uri = doc.location.href;
    var re = new RegExp(”^[A-Za-z0-9.-]+://([^/]+)”);
    var res = uri.match(re);
    return res && res[0];
    },
    preview: function(pblock) {
    var msg = ‘Go to: “${rootUri}“‘;
    pblock.innerHTML = CmdUtils.renderTemplate( msg, {rootUri: this._root()} );
    },
    execute: function() {
    doc.location = this._root();
    }
    })

  7. https://www.squarefree.com/bookmarklets/misc.html#top has been around forever, to save you some time in the future. There’s a ton more great ones on that site.

  8. javascript:location.pathname = “”; void 0

    is also much simpler :)

  9. Stu

    Or.. just click on the logo of the website, will do it for 90% of websites

  10. Randall Merkin

    Hi I tried dragging it to my address bar but I got this error:

    [an error occurred while processing this directive]

    Please check your code works in IE

  11. OJ

    Or you could use the location bar plugin for Firefox. Does this and WAY more.

  12. Maray

    Thank you !!!!

  13. SueDoc

    Wonderful! Thank you!

  14. buccia

    Also, the Vimperator plugin for Firefox does this (and also single-level-up) with the gu and gU keys.

  15. Thanks, so much!

  16. Pretty cool. Thanks!

  17. This is very sad code. It is obvious you haven’t worked with javascript very much. For instance, location.href alread returns a string always. This code could be greatly simplified:

    javascript:location.href = location.protocol + ‘//’ + location.host

  18. billy

    Thanks everyone for the comments, suggestions and other product advice.

    Fearphage — there’s always multiple ways to do something. That doesn’t make one worse than the other. location.host adds the port to the URL — I find that ugly.

Reply to “Go to Home”