bbqchickenrobot
bbqchickenrobot

Reputation: 3709

Open New Window from aspx page from *any* URL

Is there any way to configure IIS or Web app to automatically open a new window when a hyperlink 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...

The reason is that it's 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 aeons 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.

Upvotes: 2

Views: 2294

Answers (3)

Mark Brackett
Mark Brackett

Reputation: 85645

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');
});

Upvotes: 4

Keltex
Keltex

Reputation: 26426

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.

Upvotes: 1

RichieHindle
RichieHindle

Reputation: 281415

<html>
<head>
<base target='_blank'>  <!-- Here's the interesting bit -->
</head>
<body>
<p><a href='http://google.com'>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>

Upvotes: 10

Related Questions