简体   繁体   English

从*任何* URL的aspx页面打开新窗口

[英]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?有没有办法配置 IIS 或 Web 应用程序以在单击超链接时自动打开一个新窗口? 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...我的问题并不像听起来那么微不足道,让我解释一下……我知道您可以在锚标记中使用 JavaScript 或target="_blank" ,但我并不总是知道锚标记何时会列在页...

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.原因是它是一个用户论坛,想想堆栈溢出 ;) 用户可能会输入一个 URL(允许)并且它不一定是已知的,或者它是在很久以前输入的并且无法分辨。

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.我很确定答案是否定的,我只需要在保存帖子/条目时分析 URL,然后将其转换为执行此操作。

<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>

IIS wouldn't have anything to do with it - short of writing a filter that would rewrite all your links. IIS 不会与它有任何关系 - 编写一个过滤器来重写您的所有链接。 I'd suggest JQuery, where it should be as easy as:我建议使用 JQuery,它应该像以下一样简单:

$(function() {
    $('A').attr('target', '_blank');
});

You could create an HTTP Module which catches the ReleaseRequestState event.您可以创建一个捕获 ReleaseRequestState 事件的 HTTP 模块。 Then you would attach a filter to your HttpResponse.然后您将过滤器附加到您的 HttpResponse。 The filter could search for <a> tags and add the target='_blank' to those which don't already have them.过滤器可以搜索<a>标签并将target='_blank'到那些还没有它们的标签中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM