admin管理员组

文章数量:1287151

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.

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.

Share Improve this question edited Oct 13, 2020 at 20:43 10 Rep 2,2707 gold badges21 silver badges33 bronze badges asked May 1, 2009 at 22:17 bbqchickenrobotbbqchickenrobot 3,7094 gold badges48 silver badges70 bronze badges 1
  • 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 Commented May 1, 2009 at 22:23
Add a ment  | 

3 Answers 3

Reset to default 10
<html>
<head>
<base target='_blank'>  <!-- Here's the interesting bit -->
</head>
<body>
<p><a href='http://google.'>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.' target='_self'>Not new window!</a></p>

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

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.

本文标签: aspnetOpen New Window from aspx page from *any* URLStack Overflow