External Links in new windows

Freshness Warning
This article is over 15 years old. It's possible that the information you read below isn't current.

Methods for changing how external links work in Movable Type templates have been previously been published by Mark Pilgrim and others, but I recently made some changes to a Movable Type installation that forces all external links to open in a new window and uses CSS to add the external site icon, so I thought I’d share the code here.

Like Mark’s method, you’ll need to use the Macro plugin and insert some macro code into your template or into a template module that is included in your templates.

<MTMacroDefine name="links" ctag="a"><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|^http:|">    <MTMacroAttr name="target" value="_blank">    <MTMacroAttr name="class" value="offsite"></MTIfMatches><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|^http://.*.yoursite.com|">    <MTMacroAttr name="target" value="_top">    <MTMacroAttr name="class" value=""></MTIfMatches><MTMacroTag rebuild="1"><MTMacroContent></a></MTMacroDefine>

Find the part that says yoursite.com and change it to your site’s URL.

Then add a bit of CSS to your stylesheet to tell browsers what to do with the “offsite” class.

.offsite {    padding-right: 9px;    background: url(aoutside.gif) no-repeat right;     color: darkgreen;}

This class adds some space after anything that uses the offsite class. The space is there to provide room for the image, which is added using the backround property.

You’ll need to create or pick an image to use as your offsite icon. For this example, I’m using one of the micro icons from WebGragpics. You might also find some of the QBullets icons suitable.

Make sure the padding for the offsite class is big enough to hold whatever icon you decide to use.

Then update your templates to activate the macro. Change your entry body and extended entries tags to look like <MTEntryBody apply_macros="1"> and <MTEntryExtended apply_macros="1">

Adam Kalsey
January 10, 2003 1:35 PM

Worse than ignoring it, some browsers really muck it up. IE 6 appears to put the "after content" inside the block instead of after the block. Basically, whatever's in the after content sits on top of what it's supposed to be after.

Trackback from Boon Kwee's Blog
February 2, 2003 8:23 PM

external links in new windows write up

Excerpt: External Links in new windows :: Kalsey Consulting Group I must get down to doing this.

Trackback from kadyellebee
February 3, 2003 9:10 PM

external links

Excerpt: Thanks to eska, I was reminded that I wanted to implement the External Links differentiation on my site. That was

Trackback from Test
February 6, 2003 1:50 AM

testing external links

Excerpt: External Links in new windows :: Kalsey Consulting Group

Trackback from Life in the Zu
March 8, 2003 11:14 AM

Testing External Links Plugin

Excerpt: I wanted to add the External Links icon to my site awhile ago, but I just got around to it today. Thanks to Kristine for leading me to the geeky instructions....

Trackback from As deep as a puddle after a hard rain
April 14, 2003 12:58 PM

Avoiding Duplicate Comments

Excerpt: Avoiding Duplicate Comments You have to be running Movable Type on a SQL database in order for this to work. and another thing... External Links in new windows I get so tired of having to add the target="blank" attribute to the links that point away fr...

Trackback from kadyellebee
April 18, 2003 3:18 PM

i heart css

Excerpt: I've been using the External Links to differentiate between offsite links, but I'd had at least one person say

Trackback from Zlinks
June 17, 2003 8:05 PM

External Links

Excerpt: External Links in new windows :: Kalsey Consulting Group...

Trackback from unblogged updates
August 30, 2003 11:23 AM

aug.30.03

Excerpt: Arrrgghh! lol I have no updates. I'm that big of a loser. I've been mucking with a whole bunch of stuff for Movable Type. Especially stuff like Opening External Links in new windows [1 & 2]. Unfortunately, no matter what...

Chris
September 7, 2003 2:07 AM

Thanks adam! This is a good solution. Just a tip to all reading this you need the regex plugin and the macro one by the look of it. regex : http://www.bradchoate.com/past/mtregex.php#000884 Looking for an icon? Send me a ping and you can use this one: http://blog.iloaf.com/archives/000107.html

Trackback from Reflective Reality
September 7, 2003 2:11 AM

External links open new windows

Excerpt: Just installed the regex and macro plugins and a macro from Adam to open links in new windows. Wanna know how? Want an Icon? read on......

Adam Kalsey
September 7, 2003 8:34 PM

All you need is Macros, the regex plugin isn't needed.

Christian
October 28, 2003 10:08 PM

Hello, I just installed MTMacro. I'm still having a difficult time trying to understand how this plugin works. I have the AXS visitor tracker on in my blog. I want to track "outside" links, and it requires me to prepend "http://mydomainname.com/axs/ax.pl?" before each link in the href attribute. ie. If I wanted to track who clicks a link to nytimes.com, I'd have href="http://mydomainname.com/axs/ax.pl?http://nytimes.com" target=_blank" I want to use this plugin to automatically prepend this to each link outside of my site because handtyping it in is such a pain. But I don't want to it to prepend to any internal links since they're all tracked anyway. And also add the target="_blank" attribute to the external links as well. Any help with be greatly appreciated! Thanks!

girlie
November 3, 2003 4:16 PM

Hmmm. So why would a space appear instead of the icon in some links? For example, the link you included to Web Graphics has a blank space where the icon should be. I have a similar situation with a link on my site. At first I thought it was the hyphen in the domain name (because your link and mine both have one), but I tested by removing the hyphen and still had the same problem.

Ben
February 11, 2007 10:43 AM

i love oll

These are the last 15 comments. Read all 17 comments here.


Your comments:

Text only, no HTML. URLs will automatically be converted to links. Your email address is required, but it will not be displayed on the site.

Name:

Not your company or your SEO link. Comments without a real name will be deleted as spam.

Email: (not displayed)

If you don't feel comfortable giving me your real email address, don't expect me to feel comfortable publishing your comment.

Website (optional):

Follow me on Twitter

Best Of

  • The mouse and me Not only is the mouse very destructive, but it's evaded all attempts to capture or kill it so far.
  • Lock-in is bad T-Mobile thinks they'll get new Hotspot customers with exclusive content and locked-in devices.
  • Newly Digital Newly Digital is an experimental writing project. I've asked 11 people to write about their early experiences with computing technology and post their essays on their weblogs. So go read, enjoy, and then contribute. This collection is open to you. Write up your own story, and then let the world know about it.
  • Pitching Bloggers Forget what you learned in your PR classes. Start acting like a human instead of a marketer, and the humans behind the blogs will respond.
  • California State Fair The California State Fair lets you buy tickets in advance from their Web site. That's good. But the site is a horror house of usability problems.
  • More of the best »

Recently Read

Get More

Subscribe | Archives

15

Recently

Stretching your team (Jun 11)
Stretching your team is one of the best ways to improve your output, your team's happiness, and your velocity. But they'll need coaching.
Physical camera shutter for Cisco Spark Board (Jul 6)
A 3d printable design for a camera shutter for a Cisco Spark Board
My Travel Coffee Setup (Jan 20)
What my travel coffee brewing setup looks like, and how you can build your own for under $100.
Turkey Legs (May 30)
Product naming gone awry.
Speaking for Geeks: Your Slides (Dec 17)
Tips and tricks for creating great slides.
Speaking for Geeks: Writing Your Talk (Dec 14)
Don’t wait until the night before the talk to write it. Crazy, I know.
Speaking for Geeks: Tell a Story (Dec 13)
Telling a story keeps your presentation focused, keeps your audience interested, and makes it easier for you to remember your talk.
Speaking for Geeks: Where to speak (Dec 11)
You've got a great idea for a talk. How do you find conferences to submit it to?

Subscribe to this site's feed.

Elsewhere

Tropo
Voice and communications platforms, including Tropo and Phono. Work.
SacStarts
The Sacramento technology startup community.
Pinewood Freak
Pinewood Derby tips and tricks

Contact

Adam Kalsey

Mobile: 916.600.2497

Email: adam AT kalsey.com

AIM or Skype: akalsey

Resume

PGP Key

©1999-2018 Adam Kalsey.
Content management by Movable Type.