views:

273

answers:

3

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!

+7  A: 
<html>
<head>
<base target='_blank'>  <!-- Here's the interesting bit -->
</head>
<body>
<p><a href='http://google.com'&gt;New window!</a></p>
</body>
</html>

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>
RichieHindle
+! - Didn't know about the base tag. http://www.w3schools.com/TAGS/tag_base.asp
Mark Brackett
+1, Knew about the base tag, but never knew you could add the target attribute. Nice.
WaldenL
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
A: 

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.

Keltex
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
+3  A: 

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');
});
Mark Brackett
Great solution too! Nifty for off setting the processing to the client side via javascript! I guess the <base> tag does this too.
bbqchickenrobot