Camillia
asked on
Disable a hyperlink
I have the code below that works in IE but not in Chrome
I found this link and if you scroll down (the last solution), it has a CSS. I tried that but now, it works in Chrome and the link is disabled, user can't click on it but in IE, it still works..
Should I have both lines of code to make it works in both IE and Chrome or is there another way of doing this?
http://forums.asp.net/p/1895263/5355741.aspx/1?Re+hyperlink+disabled+works+in+IE+but+not+in+Chrome+or+Firefox
myherplink.Disabled = true;
I found this link and if you scroll down (the last solution), it has a CSS. I tried that but now, it works in Chrome and the link is disabled, user can't click on it but in IE, it still works..
myherplink.Attributes.Add("style", "pointer-events: none;cursor: default;");
Should I have both lines of code to make it works in both IE and Chrome or is there another way of doing this?
http://forums.asp.net/p/1895263/5355741.aspx/1?Re+hyperlink+disabled+works+in+IE+but+not+in+Chrome+or+Firefox
Another approach,with tooltip
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.disabled
{
cursor:pointer;
text-decoration:underline;
color:Gray;
}
</style>
<script>
function DisableField() {
hypLoadFav = document.getElementById("HyperLink1");
//hypLoadFav.setAttribute("onclick", "return false;");
hypLoadFav.removeAttribute('href');
hypLoadFav.className = "disabled";
hypLoadFav.title = "disabled";
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" href="123.aspx">HyperLink</asp:HyperLink><br />
<input type="button" id="adsf" onclick="DisableField();" value="disabled"/>
</div>
</form>
</body>
</html>
ASKER
Is there anyway I can do that in code behind because I need to check for some flags from the database..I think I need to somehow call the function in code behind and add it to the attribute...something like that...in the line below...
myherplink.Attributes.Add( "style", "pointer-events: none;cursor: default;");
myherplink.Attributes.Add(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window