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

29 thoughts on “Go to Home

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

  2. 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();
    }
    })

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

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

  5. Pingback: One genius little button that’s saving me a whole bunch of time

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

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

  8. i have a bookmarklet to go ‘up’ one site lvl, though what i really looking for was..This =DD thanks very much =))

    just in case, here’s the bkmlt =)

    /* up */
    javascript:l=document.location,L=false,h=l.href,S=’/',s=l.protocol+S+S,d=l.pathname,i=d.indexOf(S),j=d.lastIndexOf(S);if%20(l.hash){L=h.replace(l.hash,”)}else%20if(l.search){L=h.replace(l.search,”)}else%20if(S==d){if(s.match(‘http’))i=’www.’;if(s.match(‘ftp’))i=’ftp.’;if(h.match(i))L=h.replace(i,”)}else%20if(j+1==d.length){L=’..’}else{L=’.'}if(L)l.assign(L);void(0)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>