隐藏状态栏的web地址

Introduction

When you move your mouse pointer on any of the link in the browser, the corresponding hyperlink is shown in the status bar. As a webmaster or developer of a web site, many times you want to hide such hyperlinks in your pages. This is needed frequently in download pages to hide the original content location or payment related pages. In this small code sample we will use ASP.NET HyperLink web control to display our links and then write code to hide them from the site visitors.

The code

As an example let us assume that you have a HyperLink control called HyperLink1 on the web form. When that control is rendered in the browser; it gets converted into an HTML <A> tag. In order to hide the URL from the end user we need to handle three of its client side events:

  • OnMouseOver
  • OnMouseMove
  • OnContextMenu

You might be wondering why we need to handle the third event. This is event is raised when user right clicks on the link. Since we want to hide the link; we also would not like the visitors to use "Copy Shortcut" option from the right click menu. Hence, we also need to handle the OnContextMenu event.

Note that these are client side events and we need to write JavaScript code to handle them. There are two steps involved in this:

  • Attach client side events and their event handler function in your server side code.
  • Write client side function to handle the events
Attaching events and event handler

In order to attach a client side event and its handler ASP.NET provides an Attributes collection. You can use this collection as follows:

HyperLink1.Attributes.Add("onmouseover","HideLink();"); 
HyperLink1.Attributes.Add("onmousemove","HideLink();");
HyperLink1.Attributes.Add("oncontextmenu","return false;");

Here, we are specifying that OnMouseOver client side event will be handled by a function called HideLink(). In the OnContextMenu event we simply want to return false to indicate as if that event never fired.

Client side function

Here is the JavaScript function that does the job for us.

function HideLink() 
{
window.status="You do not see the link here!";
}

Here, we simply set the status bar text of the browser window to some custom text. That's it.

Download

You can download the complete sample code of this article. Just click on the download link at the top of this article.

Summary

In this small article we saw how one can hide hyperlinks in the client browser using ASP.NET controls and JavaScript.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值