Hyperlink的target属性原来可以这么用 --zt

也许是我大惊小怪,我现在才发现 hyperlink的target属性可以这么用

大家可以看一下 asp.net ASP.NET Articles -- Updated Daily! ,点击链接在新窗口中打开某一篇文章,不要关闭打开的新窗口,点击另外一篇文章的链接,可以发现新的链接不会打开新的窗口,而是在先前打开的窗口中加载,这样我们就可以防止打开过多的新的窗口。
好奇,看了一下源代码,没有什么特别,可是我查了一下msdn, 发现target属性解释如下:

Possible Values

sTargetString that specifies or receives one of the following values.
nameThe name of the target window or frame.
_blankLoad the linked document into a new blank window. This window is not named.
_mediaLoad the linked document into the HTML content area of the Media Bar. Available in Internet Explorer 6 or later.
_parentLoad the linked document into the immediate parent of the document the link is in.
_searchLoad the linked document into the browser search pane. Available in Internet Explorer 5 or later.
_selfDefault. Load the linked document into the window in which the link was clicked (the active window).
_topLoad the linked document into the topmost window.

The property is read/write. The property has a default value of _self.

看看我上面标注为红色部分就知道是为什么了。asp.net的文章列表中的hyperlink设置了这样的属性 target="_new"。

试试下面的代码,我也作出了同样的效果
AspnetUpload.net
Upload4Asp.net

不过有一点不好,就是我打开新页面之后,再次返回主页面点击其它链接,虽然新的链接已经加载,但是并不自动获得焦点而是停留在主页面。想了个办法解决,就是在打开的新页面中加一点javascript代码:

None.gif       < script language = javascript >
None.gif     

None.gif
      < SPAN>script>
获取或设置单击 HyperLink 控件时链接到的 URL。

命名空间:System.Web.UI.WebControls

程序集:System.Web(在 system.web.dll 中)

属性值
单击 HyperLink 控件时链接到的 URL。默认值为空字符串 ("")。

示例

<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

</head>
<body>

   <h3>HyperLink Example</h3>

   Click on the HyperLink:<br> 

   <asp:HyperLink id="hyperlink1"
                  ImageUrl="images/pict.jpg"
                  NavigateUrl="http://www.microsoft.com"
                  Text="Microsoft Official Site"
                  Target="_new"
                  runat="server"/>      

</body>
</html>

版本信息

.NET Framework
受以下版本支持:2.0、1.1、1.0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值