How to disable Anchor tag in IE and Firefox?

Posted: September 16, 2009 in ASP.NET, Javascript
Tags: , ,

I have searched many sites for to disable anchor and I know that IE supports ‘disable’ property for anchor tag, however Firefox does not support this. So whenever you try with ‘disable’ property of an anchor tag “<a></a>” you will get proper output in IE browser but not in Firefox browsers.

I have found a very good article which disables the anchor tag using few tricks because without tricks it is not possible to mange disable anchor in Firefox. You can find this article here. However, you can copy the same javascript script of above article as below.
function disableAnchor(obj, disable){
var href = obj.getAttribute("href");
if(href && href != "" && href != null){
obj.setAttribute('href_bak', href);
obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);"blue";

Also note that you can perform the same thing on the code behind (for if you are using a server control for anchor tag and you want to disable the anchor, you just need to remove the ‘href’ property using  MyAnchor.Attributes.Remove("href") and then just apply gray color to anchor and its done. It will work in both IE and Firefox (javascript and server code both).

Happy Programming!!

  1. Hello there,
    Cool site, I just came across it and I’m already a fan.

  2. REIT says:

    I usually don’t post on Blogs but ya forced me to, great info.. excellent! … I’ll add a backlink and bookmark your site. 🙂

  3. sarbjeet says:


    function disableAnchor(obj, disable){
    var href = obj.getAttribute(“href”);
    if(href && href != “” && href != null){
    obj.setAttribute(‘href_bak’, href);
    obj.setAttribute(‘href’, obj.attributes[‘href_bak’].nodeValue);”blue”;

    but this script is not running well and provide the error.

  4. ram says:

    not working..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s