Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: DISABLED Attribute Does Not Disable Hyperlinks


View products that this article applies to.

Symptoms

Although the DISABLED attribute is set to true for a hyperlink, as in the following,
<a DISABLED="true" href="http://www.microsoft.com/">Where do you want to go today?</a>
				
users can still click on the hyperlink and Internet Explorer navigates to the selected page.

↑ Back to the top


Resolution

To resolve this problem, set an onclick event for the hyperlink that returns either true or false depending on the current execution context. The following code sets the value of a global Microsoft JScript variable to true or false, depending on a button click. The target hyperlink object's DISABLED property is updated so that it can properly communicate its disabled status to other objects and script functions on the page.
<html>

<head>
<title>Workaround for DISABLED Attribute Problem</title>

<SCRIPT>

var canNav = false;

function canNavigate() {
	return canNav;
}

function load() {
	document.all("btn1").innerText = "Link status == " + canNav;
}

function setNavigate(linkObj, canNavParam) {
	if (linkObj != null) {
		if (canNavParam == false) {
			linkObj.disabled = true;
		} else {
			linkObj.disabled = false;
		}
		canNav = canNavParam;
	} 
}

function updateBtnStatus(btnName) {
	var btn = document.all(btnName);
	if (btn != null) {
		document.all(btnName).innerText = "Link status == " + canNav;
	}
}

</SCRIPT>

</head>

<body onload="load();">

<a id="lnk1" disabled=true href="http://www.microsoft.com/" onclick="return canNavigate();">Click  here</a><p>

<button id=btn1 onclick="setNavigate(document.all('lnk1'), !(canNav));updateBtnStatus('btn1');">
</button>


</body>

</html>
				

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites: (c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Jay Andrew Allen, Microsoft Corporation.

↑ Back to the top


Article Info
Article ID : 253579
Revision : 4
Created on : 1/1/0001
Published on : 1/1/0001
Exists online : False
Views : 267