[an error occurred while processing this directive].com

22Mar/0827

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):

Go to Home

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 :)

Filed under: code Leave a comment
Comments (27) Trackbacks (1)
  1. I didn’t realize I needed this until I saw it. Thank you, clever man.

  2. 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. Thanks! This is one of those things you wonder how you did without.

  4. Um… brilliant. Fucking brilliant.

  5. 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. 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. Or.. just click on the logo of the website, will do it for 90% of websites

  10. 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. Or you could use the location bar plugin for Firefox. Does this and WAY more.

  12. Thank you !!!!

  13. Wonderful! Thank you!

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

  15. Pretty cool. Thanks!

  16. 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

  17. 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.

  18. Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  19. usual calcium supplementation in thyroidectomy patients Order Clomid (Serophene) unwed mothers safe drug nj lynx diet low heart beats
    http://rxdrugs24x7.com/product/enmobil-cream.html

  20. county of san joaquin medical social worker 0539 Order Levlen diabetic tendencies chromium hoodia diet pills catholic depression
    http://rxdrugs24x7.com/product/eldepryl.html


Leave a comment