tips and tricks for movable type
open links in new window with regex
June 01, 2003
If you prefer to have links in entries and comments open in new windows, you can automatically add target="_blank" to them using Brad Choate's nifty Regex plugin.
Regex statement:
Application to tags:
<MTEntryMore regex="1">
<MTCommentBody regex="1">
Note: You'll need to make sure your Sanitize Specs include a href target, or the target="_blank" will be stripped from the URLs in the comments.
TrackBack: 8
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/152)
» New design is live
Excerpt: My new design is live and everyone likes it! I only have 2 templates for finish, archives main index and...
Weblog: Breaking Windows
Tracked: 06.18.03 04:14 AM
» ..site work...
Excerpt: I recently added several features to the blog: Browseable monthly archives from the calendar (the arrows next to month)Fixed up some CSSUpgraded my gallery to latest developement of Apache::GalleryMade it so all links going to other sites automatically...
Weblog: is a geek
Tracked: 08.18.03 11:12 AM
» target="_blank"
Excerpt: if you're like me - thinking that it's great assigning a target=_"blank" on every link, I have a tips found...
Weblog: me-me-me
Tracked: 08.24.03 07:51 AM
» Camera, Fish and Plugins - Oh My!!
Excerpt: I took a few more pictures last night after I posted. Just some of Ashey laying around. Something interesting about the Rebel is that the only way I found to turn off flash is on the control knob. The spinny...
Weblog: is a geek
Tracked: 09.23.03 09:52 AM
» BLOG | SKLLS | thegirliematters
Excerpt: [the girlie matters] tips and tricks: open links in new window with regex...
Weblog: publc blog
Tracked: 12.20.03 08:36 AM
» Slow day ...
Excerpt: It's a slow day at work today so I spent some time playing with MT and adding more useless *features* to my blog. Firstly, you can now add yourself to わさび.com notifications list. If you do - you will receive...
Weblog: わさび
Tracked: 01.13.04 10:37 AM
» links will now pop up
Excerpt: Links will now pop up in a new window. Thanks to thegirliethatmatters There ya go Char. If people hate it, let me know. I can always remove it :) But no, I do not know how to make it optional...
Weblog: Friends
Tracked: 02.23.04 05:09 PM
» More about Links
Excerpt: Obviously, my little speech about links opening in new windows isn't going to convince everyone. All the same, I'm getting really tired of seeing people share tips on how to easily get links to open in new windows. In an...
Weblog: So Very Posh
Tracked: 04.16.04 09:45 AM
Comments
hey,
sweet mt tips u'got here. i stole a couple of 'em and just wanted to say thx for letting me ;)
Once again, u rock!
i've been trying to use this plugin, but i don't understand "application of tags". which template do i use? why are there no $ in these tags anymore? sorry for all these questions. and where do i put the regex statement? thanks so much...
Yeah, I don't understand where I put the regex statement in at either. This has gotten me really confused. Do you place it before every link that you want to open in a new window???? I am trying to get my author's name as a link to their url, to open in a new window and I am just completely lost on how this works. I wish I had a fraction of your brain. hehe..
Well, this tip assumes you've downloaded and installed Regex, as well as reading the documentation that accompanies it. <wink>
Put the Regex statement in the same template where you've got the other tags.
"Application of tags" means that's what you need to change the tags to look like in order to apply the Regex to those tags.
Teresa - the $ are optional in MT tags.
Thanks for this tip (and for all the rest of your tips and tricks, for that matter)! It's just what I've been looking for.
Thank so much...I have been doing this by hand for ALL links in my blog...what a PITA!!!
Thanks for the help and great site!!!
I'm another who doesn't use Regex. But you did provide me on the MT forum with another way to include the _blank to any link in my entries, when I use the URL button so I thought I'd add it here as it works very well:
You can hack the insertLink function in tmpl/cms/edit_entry.tmpl.
function insertLink () {
if (!document.selection) return;
var str = document.selection.createRange().text;
if (!str) return;
var my_link = prompt('<MT_TRANS phrase="Enter URL:">', 'http://');
if (my_link != null)
document.selection.createRange().text = '<a href="' + my_link + '" target="_blank">' + str + '</a>';
}
I used your code successfully on the first two, but I can't figure out where I should put it to affect my php include sidebar. Also, is CommentBody in the main template?
Thanks
I tried the same approach to automatically add borders to images in my entries, which were already defined in CSS. I used the following syntax:
s|img|a class=\"imgbdr\" img|g
That didn't work and actually removed images and instead applied class="center" to some text that normally followed the images in the entry. Any suggestions would be highly appreciated.
WOOOOT! Even though I do not have Regex, I found the answer I needed in your comments.
Your site is the bible, I adore it!
I really don't get how to work regex. I've installed it onto my server, but I have no idea who to get it to work so my links in my comments open in new windows. I will say I'm quite new to MT, but I have looked everywhere and even though there are places explaining it, I have no idea how to take in the information.
I put s|a href|a target=\"_blank\" href|g
into my comment listing template. With in the MTcommentbody area. But I still can't get the links to open in new windows.
Can someone explain in non-jargon. With simple easy & step by step instructions for me, the dumb newbie...
sorry ^^;
Saya, did you see the note in my entry about adjusting your Sanitize Specs?
Hello, I just wanted you to know that I love your site. I just graduated from grad school at RIT and I did my thesis on MT and used your site for a bunch of help. I have just added that regex plugin to a project I am doing for a friend, and it works great, but I wanted to know how you guys got that trendy looking icon next to the links?