One Mom’s Journey from Fat to Skinny to Confident


Follow up: Links Opening New Windows/Tabs—JQuery Saves the Day!

6 Comments 1213 views

Sorry for my short hiatus. I’ve been consumed with baby and conference.

Anyway, I loved getting all the opinions on opening links within posts to a new window or tab. I’m gonna be honest here, the comments really made me feel like an old fart set in her ways.

So I decided to at least try and set inline post links to "_blank"–that’s the attribute that opens them in a new window/tab based on the browser.

There was only one problem. I have years of content. Thousands of posts. How do I change the setting globally?

Cue JQuery!

I’ve talked about JQuery once before. It’s an awesome JavaScript library that simplifies things like animation and document traversing. I don’t develop full time anymore so I’m no expert with it but when there are small tasks I need to do–like modifying all the links in my posts–it’s the first place I go.

So instead of hand editing thousands of links on my blogs I simply wrote the following line of code…

$('.entry a').attr('target', '_blank');

That one line sets the attribute target to _blank in all a tags (links) found within the class entry.

Seriously.. how stinkin’ cool is that?!?

I’ve added this small script to Roni’s Weigh, GreenLiteBites and here on Now all links open in a new tab/window!

The best part… If I change my mind all I need to do is delete the code and all goes back to "normal". In my opinion, that’s the best part as I’m not completely sold on this just yet.

I told you. I’m set in my ways.

Leave a comment

I’d love to hear your story or thoughts on mine.

However, to prevent the massive amounts of spam I was receiving I have turned off comments on any post older than 5 days old. If you'd like to leave me a note regarding this post or anything really try me on twitter (@RoniNoone,) my Facebook page, or even IG (@RoniNoone) I'm so sorry for the inconvenience. I never thought I'd have to do this but it's gotten way out of hand and comment management has become simply too time consuming to manage.


There are 6 comments so far.

    Tim Wilson

    April 28, 2011

    I ended up going a bit further when I made changes to my blog earlier this month.

    I have been manually editing all my links for years to do with them what I want them to do. I found that most internal links I did not want to open a new window/tab, but all external links I did.

    I used jQuery as well, but a little bit more than just telling it to open all links in a new window/tab it only does it for links that are not in my domain.

    This is the code I used, and I have found that I am much more productive when I post. I don’t have to do the html edits before posting…. I just post!

    I opted to not include the small icon because I didn’t want it to mess with my layout anywhere. I also chose to do it on my entire site because there are some links in my sidebar that with blogger I cannot override to open new windows/tabs and this fixed that for me. The fact that it keeps all local urls in the same page keeps all my menus from breaking.

    Just figured I would pass this along :)

    Tim Wilson

    April 28, 2011

    I just found another place you may want to put that code – in your comments section :)

    Krista S.

    April 28, 2011

    Yay! =) One of the things that makes you such an awesome blogger to follow is that you LISTEN to your readers even if you don’t always agree with us.


    April 28, 2011

    Roni, you have no idea how incredibly happy it makes me when links open in new tabs. Sometimes I want to follow the link but I don’t want to lose my place and I know that I can just right click and open in new tab but I just love it as a default. I know nothing about programming but this sounds like an easy solution!

    shandy (@webgals)

    April 28, 2011

    That’s awesome! I may just use that code. :)


    April 29, 2011

    OK… so I read this yesterday, but wanted to observe my own behaviors for commenting. Here’s what I realized:

    I want all links to open in a new tab, except when I am clicking away from active media (videos/music/animations etc…) because typically when I leave those pages I want the media to stop. In the few instances that I don’t want this media to stop playing, I will command + click to open in a new tab. Just my two cents.

    When I interact with all of your various blogs Roni, I always command click on most of your links to open in a new tab so that I can finish reading the current article and then look at the referenced links after I am finished reading.

    Way to go running your own focus group! ;)