Take the 2-minute tour ×

Is there any way to configure IIS or Web app to automatically open a new window when a hyper link is clicked? My issue isn't as trivial as it sounds, let me explain... I understand you can use javascript or target="_blank" in the anchor tag, but I don't always know when an anchor tag might be listed on the page...

Reason is that its a user forum, think of stack overflow ;) where a user might enter a URL (allowed) and it's not necessarily known, or it was entered eons ago and there is no way to tell.

I'm pretty sure the answer is no and i'll just have to analyze for URLs when the post/entry is being saved and convert it to do this then... any tips are appreciated!

share|improve this question
Or I suppose I could analyze HTML content being written to the page for a URL and then add the appropriate code... hmmm... there has to be someone who has tried this already and discovered some nifty pattern to solve this. –  bbqchickenrobot May 1 '09 at 22:23
add comment

3 Answers

up vote 9 down vote accepted
<base target='_blank'>  <!-- Here's the interesting bit -->
<p><a href='http://google.com'>New window!</a></p>

Of course that really will do all links - if you want a link to be an exception to the rule, and to open in the current window, do this:

<p><a href='http://google.com' target='_self'>Not new window!</a></p>
share|improve this answer
+! - Didn't know about the base tag. w3schools.com/TAGS/tag_base.asp –  Mark Brackett May 1 '09 at 22:26
+1, Knew about the base tag, but never knew you could add the target attribute. Nice. –  Walden Leverich May 1 '09 at 22:28
Cool. I pretty much know about all of the links I create programatically on my page (i.e. urlrewriting, etc...) so I can easily add the target="_self" tag to those! Thanks for a simple solution - completely didn't even consider HTML to have the answer lol. –  bbqchickenrobot May 5 '09 at 1:15
add comment

IIS wouldn't have anything to do with it - short of writing a filter that would rewrite all your links. I'd suggest JQuery, where it should be as easy as:

$(function() {
    $('A').attr('target', '_blank');
share|improve this answer
Great solution too! Nifty for off setting the processing to the client side via javascript! I guess the <base> tag does this too. –  bbqchickenrobot May 5 '09 at 1:14
add comment

You could create an HTTP Module which catches the ReleaseRequestState event. Then you would attach a filter to your HttpResponse. The filter could search for <a> tags and add the target='_blank' to those which don't already have them.

share|improve this answer
Cool idea, adds processing to the server, but nice to see a third way to get it done, thanks for all the replices guys, you all rock!! –  bbqchickenrobot May 5 '09 at 1:14
add comment

Your Answer


